Skip to main content

Questions tagged [prototype]

In prototype-based languages, the prototype of an object is a set of properties which is inherited by all objects which are based on this object. Not to be confused with [function-prototype], [prototype-js], [prototype-pattern], [prototype-scope] or [prototypejs]; see the full info for details.

1 vote
0 answers
24 views

Letting Typescript recognize new methods added through Object.prototype

I would like for typescript to recognize changes I make to the Object.prototype. Ideally, I would like to be able to do something like: Object.prototype.l = function (title: string) => { ...
cayge sinnett's user avatar
-1 votes
1 answer
67 views

How does one implement a callable class with a single own method?

Explanation of the idea : I would like to build a class that can be called like a function without initializing it as an instance. For example, I want to create a class named logger and use it in two ...
Weelpert's user avatar
0 votes
1 answer
48 views

Setting Prototype Object of a Constructor function vs Prototype Object of a Class In JS?

So, I was learning about Prototypes and OOPS concept in javascript. WHile playing around with prototypes, I came across this weird behaviour(weird because I am unaware of the concepts :) ). The code ...
curiousmind's user avatar
1 vote
1 answer
38 views

Prototype pollution between functions and plain objects

There seems to be some asymmetry in prototype pollution between functions and "plain"1 objects: var a = {} function foo(){} a.__proto__.something = 32; foo.__proto__.bar = 67; console....
OrenIshShalom's user avatar
0 votes
0 answers
23 views

TypeError: Cannot read properties of undefined (reading 'prototype') at ./node_modules/http2/lib/protocol/framer.js

In the next Github Repo I am getting the TypeError: Cannot read properties of undefined (reading 'prototype') at ./node_modules/http2/lib/protocol/framer.js based on the code, I believe the ...
Jack Harty's user avatar
0 votes
1 answer
31 views

What is the correct way to inherit from a prototype?

I have 2 "classes": const Person = function(firstName, birthYear){ this.firstName = firstName; this.birthYear = birthYear; } Person.prototype.sayHi = function(){ console.log('Hi!'); } ...
Vsevolod IV's user avatar
0 votes
0 answers
43 views

How do I write a new method that changes the number it is used on?

Here's what I've tested: function testRounding() { var order = { size1: 0.07529999999999999, size2: 0.07529999999999999 }; order.size1 = order.size1.roundDecimal(4); order.size2.roundDecimal(4); ...
Alex Libengood's user avatar
0 votes
1 answer
33 views

Mocking an async builder pattern API with proxy

I'm trying to mock knex for testing. Everything seems to work but attaching a proxy to an array as prototype seems to remove the iteratability of arrays. Here is the mock function. Following works ...
srinesha's user avatar
1 vote
2 answers
79 views

Using prototypes to check whether an object is an instance of a class

I tried to solve the 2618s problem in LeetCode https://leetcode.com/problems/check-if-object-instance-of-class/description/ and wanted to know if there is a way to resolve it using only properties ...
ioneluoooo's user avatar
1 vote
0 answers
37 views

Invalid behavior of object.assign [duplicate]

Why does the following prints "222"? class MyClass { print() { console.log(111); } } const n = new MyClass(); const a = { print() { console.log(222); }, } Object.assign(a,...
Naor's user avatar
  • 23.8k
0 votes
1 answer
100 views

unable to get or set the properties of prototype

I am getting error when trying to get the keys of the object and all the objects of prototype objects, if present. It gives me an type error when trying to access keys of prototype. Whats wrong This ...
Gary's user avatar
  • 2,333
2 votes
0 answers
54 views

Javascript: Augment a standard class without global prototype changes

A classic "bad idea" in JS is to alter the prototypes of inbuilt types: Array.prototype.last = function() { return this[this.length - 1] }; [1,2,3].last() // 3 In ES6 we can extend the ...
Kaia's user avatar
  • 908
0 votes
0 answers
12 views

Document custom methods primitive types in Javascript

I have defined some methods on primitive types for my project: Object.defineProperties(String.prototype, { capitalize: { value: function () { return this.charAt(0).toUpperCase()...
Resen's user avatar
  • 1
-2 votes
1 answer
55 views

Error about the Redefinition of a struct and conflicting types for a function

I have a given header (given1.h) file that includes my function prototypes, definitions, a struct definition, and libraries. I wanted to add a helper file called helper.h that incldues a function ...
RelaxeddYeti's user avatar
0 votes
0 answers
10 views

What are the ways to mark a bean (Prototype) in Spring for deletion? [duplicate]

When we specify a bean with a - prototype scope, Spring does not monitor the lifecycle of such a component. However, I cannot use scope Request or Session. How can we tell Spring that such a component ...
skyho's user avatar
  • 1,815

15 30 50 per page
1
2 3 4 5
363