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.

Filter by
Sorted by
Tagged with
2 votes
2 answers
82 views

Why is `sort List::Util::uniq(BAR, BAZ);` different from `sort &List::Util::uniq(BAR, BAZ);`

I know & disables prototypes on but doesn't parentheses also do that. How are These two blocks of code different, and is there a reason that the top can NOT act like the bottom, use List::Util; ...
Evan Carroll's user avatar
  • 79.4k
1 vote
0 answers
13 views

How to get prototype for decorator?

I have a typescript classes: class InnerClassA { property1: string; property2: number; } class InnerClassB { property3: boolean; property4: string; } class ABC { innerA: InnerClassA; ...
Vlad's user avatar
  • 862
0 votes
2 answers
100 views

How can I override the behavior of valueOf() as a prototype of the Number in JavaScript?

I was given a task to understand the .toString and .valueOf methods, who calls them, where they are used, how they work, how they are called and how to change calling sequence. I am getting an error ...
yarslvd's user avatar
0 votes
0 answers
28 views

Nodejs how to get the prototype of a function like the debugger

In Nodejs, I am trying to get the prototype name of a function defined like: AgreementSchema.statics.saveAgreement = function(){...} When I check the Web-storm debugger, it can fetch the type of it ...
bugdayci's user avatar
  • 948
1 vote
0 answers
33 views

How to see JS prototype in VS Code using Code Runner extension?

I am a beginner currently going through a JS tutorial on prototypes but I am unable to see the prototype property after running the code in VS with Code Runner. Is it not possible to see prototypes in ...
Dariable's user avatar
0 votes
1 answer
43 views

Hijacking addEventListener results in too much recursion when adding a react-invokeguardedcallback listener to HTMLUnknownElement

I have a use case where I'd like to monitor event listeners being added. I found a method to do this that worked for me here: https://stackoverflow.com/a/6434924 This code seems to work in many ...
user2041427's user avatar
0 votes
1 answer
57 views

On the prototype chain of an object, some objects' .constructor.prototype doesn't point to its [[prototype]], but points to that object itself

The source object that printing the prototype chain can be various: [1, 2, 3] // array literal {a: 1} // object literal new Set() // built-in set new Promise( () =>{} ) // built-in Promise ...
Zhang Wei's user avatar
-1 votes
2 answers
52 views

Will change of constructor's prototype influence the instantiated object?

If I have a function (constructor) with a defined prototype, let's say: function Student(name) { this.name = name; } Student.prototype.sayHello = function() { console.log(`Hello, my name is ${...
McBacon's user avatar
1 vote
1 answer
59 views

Accessing __proto__ on a function returns a function

Consider the following code : function objectFunction() { this.x = 2; } console.log(Object.keys(objectFunction)); console.log(objectFunction.__proto__, objectFunction.prototype); Why am i ...
Shekhar Dangi's user avatar
1 vote
2 answers
46 views

Making new strings with array data

I am trying to solve this problem where if age > 18 it returns name + can go to the matrix or if age < 18 returns they are under age: function makeStrings(arr){ // your code here } console....
Caelan Quigley's user avatar
-1 votes
3 answers
46 views

Why Object.isPrototypeOf not available in normal objects

I am able to access Object.getPrototypeOf method, but why is the same not available for instantiated objects? const obj = {} obj.getPrototypeOf // is not a function
Murtaza Raja's user avatar
0 votes
1 answer
49 views

How to design a horizontal scrolling bar for random selections on Figma?

I am trying to design a cooking app in Figma and one of the screens I wanted to do a surprise me funcion where there are 4 categories (cuisine type, main protein, vegetables, and carbs) and they ...
Dani G's user avatar
  • 1
0 votes
2 answers
32 views

Why does JS throw TypeError for Class Instances but doesn't do anything in case of Object Literals when tried to override Non-writable Data Property?

Foreword Going through MDN Docs, I found 2 interesting points about object property inheritance in JS. The article on Object.defineProperty() points out that Unlike accessor properties, data ...
Perspicacious's user avatar
1 vote
1 answer
28 views

Is there a syntax in JavaScript class definitions to declare a property on the prototype?

I know that data properties on prototype objects are considered an anti-pattern, but there are some use cases. One is the @@toStringTag property, which is used by Object.prototype.toString() to return ...
Rolf's user avatar
  • 769
0 votes
0 answers
24 views

Prototypes chain differences between Firefox and Chrome console [duplicate]

When we try to log a custom prototypes chain, made with custom constructor functions, the Chrome console will display it in a very illogical way. Here is the code where I create two constructor ...
J.doe's user avatar
  • 115
1 vote
1 answer
156 views

Implement the Filter method on a Prototype

I have to filter a prototype without using the .filter method. I thought that I had it, but it gave me a mistake in one of the tests, I checked the answer, but I don't fully understand it and when i ...
Meigu's user avatar
  • 39
0 votes
2 answers
53 views

Prototype extension doesn't work when Angular app is deployed

Since I have a C# backend, I thought of applying a C# principle to the Angular frontend, so I came up with this: declare interface Date { addDays(days: number): Date; addYears(years: number): ...
nonnodacciaio's user avatar
0 votes
1 answer
57 views

How to invoke an object like a function in Javascript? [duplicate]

Suppose you have a function: const myFunc = function () { console.log('Function has been invoked'); } You are able to invoke a function by using parentheses as myFunc(). Now suppose you have an ...
grentank's user avatar
0 votes
0 answers
40 views

Overriding `Function.prototype.toString` in JSDOM for a specific function

I'm using JSDOM and trying to mock the behavior of window.Function.prototype.toString.call(window.WebGLRenderingContext.prototype.getParameter). I want it to return 'function getParameter() { [native ...
Jay's user avatar
  • 1
1 vote
1 answer
84 views

why should we include the header file in the same source where we implemented the functions? [duplicate]

lately, I had to learn C lang, when I reached the header file section I noticed that I have to include the header file that contains prototypes in the calling source and also in the source file where ...
elakhdar_ayoub's user avatar
0 votes
0 answers
39 views

Why don't i get _ _ proto _ _ when i console log in chrome rather i get [[ Prototype ]] [duplicate]

i was watching a video of colorcode and when he is doing console.log for an array he is getting proto but i am getting [[Prototype]]. -----------------VS----------------
JalajYadav_Avesta's user avatar
1 vote
2 answers
95 views

What do people mean when they say `Map` is ‘not susceptible to prototype pollution’?

Regarding the security of JavaScript Maps, there exist claims like these: The Map primitive was introduced in ES6. The Map data structure stores key/value pairs, and it is not susceptible to ...
steveluscher's user avatar
  • 4,142
-1 votes
2 answers
27 views

why if (built-in object)Object executed as a function with parameter, it outputs array named 'String'?

let test=new Object('test') console.log(test) // String{'test'} which is array. // if I log like below console.log(test[0]) //'t' console.log(test[1]) //'e' console.log(test[2]) //'s' console.log(...
LICON99's user avatar
  • 29
1 vote
1 answer
141 views

Javascript: prototype function, changing variables - becomes NaN

With this code, when pressing a key, 'index' become NaN. Why, and how to do it correctly? const Key = function(){ this.Index = 0; } Key.prototype.storeKey = function(key){ this.Index++; ...
WhyNot's user avatar
  • 21
0 votes
1 answer
78 views

How to avoid mentioning a function pointer's arguments inside the definition of a function that takes it as argument?

I'm writing this C code that involves passing around a lot of function pointers, and sometimes writing all the arguments that a function pointer takes when defining a function that takes it as an ...
Mehdi Charife's user avatar
0 votes
1 answer
48 views

JavaScript: Object Insepection with the Prototype Chain

The browser console allows you to inspect an object using a tree structure, for example like this: console.log(document); I can then freely browse the object, including its prototype, and the ...
Ood's user avatar
  • 1,658
0 votes
1 answer
29 views

Unable to assign to the value of `this` for a string prototype definition

Unable to assign to the value of this for a string prototype definition. function testfunction(thisValue) { thisValue = thisValue || this; thisValue = "new test"; console.log(...
Gary's user avatar
  • 2,303
0 votes
2 answers
90 views

Why does [[prototype]] has two level of __proto__ in javascript objects?

When we create an object and look at the [[prototype]] of it, there is a __proto__ property and even further we expand there is the same set of properties with another __proto__ but with the null ...
user2613946's user avatar
0 votes
4 answers
236 views

Is it usual to declare the arguments in a function prototype?

I know that it is possible to declare function prototypes without arguments. And I'm not seeing any benefit in using them in my codes. Are there any popular recommendations regarding the use of ...
Demétrios Guimarães's user avatar
0 votes
0 answers
135 views

The typeUrl_ and value_ in google.protobuf.Any in the response received by the grpc java client from the server are empty

There is a GRPC call, the server is implemented by golang, and the client is implemented by Java. The response defined by the server contains a google.protobuf.Any attribute. After receiving the ...
Hxd Legend's user avatar
0 votes
1 answer
118 views

What's the right way to set up prototype chain in JS

I am trying to set up a prototype chain in Js with the following code. const personBaseObject = { firstName: null, lastName: null, introduceSelf() { console.log(`Hi, I am ${this....
kbl's user avatar
  • 159
0 votes
0 answers
21 views

Inheritance of super constructor methods

Let me explain what I think going on: We create constructor User and add info() to it's prototype We create UserAdmin constructor and by calling User.call(this, name); we call User constructor to ...
Boris Borais's user avatar
1 vote
1 answer
50 views

Error: adding forEach in object prototype makes it readonly

I'd like to extend the object prototype, adding the forEach method. I followed this guide here, but this causes other stuff creating prototypes forEach to fail. In my example I got the error with RxJS....
OtaconKiko's user avatar
0 votes
2 answers
144 views

Why do instance fields belong to the instances instead of their prototype?

In the JavaScript class syntax introduced in ES6 (static properties are accessible from the class, instance properties are accessible from the instances): static fields belong to the class; static ...
Géry Ogam's user avatar
  • 6,592
0 votes
0 answers
24 views

Injecting Singleton services into Prototype Bean

I have this code: Caller: public class MyManager { @Inject private ObjectProvider<MyService> mySvcProvider; public void processMyData(){ MyService mySvc = mySvcProvider.getObject("...
Nila's user avatar
  • 71
0 votes
0 answers
21 views

prototype_data values are deleted when the form is submitted

I will take an example to illustrate my problem. I have a recipe linked to ingredients. I create a form with a CollectionType of ingredients. I create a prototype_data, I create my object and in the ...
Jiizen's user avatar
  • 119
0 votes
1 answer
44 views

Add typed function to array prototype

I have a function written in typescript which takes an array of type (T | undefined)[] and filters out all undefined values, so that the resulting type is only T. function filterUndefined<T>(ts: ...
pietsch's user avatar
  • 50
0 votes
0 answers
44 views

Does all Object refers to same Prototype Object on top of prototype chain in javascript?

I run following code and it looks like ultimately all objects have same object prototype on top of prototype chain and then this prototype point to null as its own prototype. does it concludes that ...
Jaikaran saini's user avatar
0 votes
0 answers
40 views

How can I create a stepper in figma or adobe xd?

So I’d like to understand how to create steppers (with component states) with a plus and minus sign (number between them, ie add or subtract from cart) that when clicked, add or subtract. I watched a ...
Elle H's user avatar
  • 1
0 votes
1 answer
25 views

How F.prototype works when I place F.prototype outside and inside initial? [duplicate]

I'm learning F.prototype throw this site. After playing around for awhile, I'm getting confused when trying to understand prototype. First, let me show my example: let animal = { jump: function () ...
Tea's user avatar
  • 873
1 vote
1 answer
53 views

Why does the getter/setter methods get inherited as a property in child object?

I was exploring the Object.create() method and came across something interesting. When I passed an Object with a getter method in it (made using get keyword), the getter method was implicitly present ...
Jay Mehta's user avatar
0 votes
0 answers
32 views

Meteor Astronomy : TypeError, Cannot read property 'prototype' of undefined

I'm asking for help here because I've been stuck on this problem for several days. https://i.stack.imgur.com/4Jk6e.png I'm using the Astronomy package in my Meteor project and after defining a new ...
Vikron's user avatar
  • 1
0 votes
0 answers
99 views

why does all Objects, variables and function share same prototype in Javascript?

I am learning about prototypes in Javascript, and while practicing it I found that when I add some method to prototype of an object, then the same function is also callable with any other variables or ...
Jaikaran saini's user avatar
0 votes
0 answers
44 views

Iterating on prototypes in typescript

I am trying to learn typescript and in my course, there is a section where my tutor is trying to create a class for login controller and I am trying to use decorators to create some kind of modular ...
Farbod Shabani's user avatar
0 votes
0 answers
39 views

Using closures to manually "extend" a class in JavaScript/TypeScript

This isn't so much a problem I'm having, rather than a general question about how classes/prototypes work in JS vs using closures. Lets say I have the following class (I'm going to omit the full body'...
hankthetank27's user avatar
0 votes
1 answer
295 views

Display of __proto__ vs [[Prototype]] in Chrome Developer Tools

I am learning Java Script and I see the examples that were published a few years ago show __proto__ in the chrome developer tool - console while explaining the prototypical inheritance concept. When I ...
Athman's user avatar
  • 5
1 vote
4 answers
158 views

Overwrite call in javascript object

I am a newbie in JavaScript, trying to extend class variable prototype without inheritance class Z{ constructor(){} a(){console.log('a')} get b(){console.log('b')} c(){console.log('c')...
Weilory's user avatar
  • 2,733
0 votes
0 answers
44 views

Difference between setting the prototype of an object using Object.create() vs assigning the prototype of one object to the prototype of another [duplicate]

function Student() { } Student.prototype.sayName = function() { console.log(this.name) } function EighthGrader(name) { this.name = name this.grade = 8 } EighthGrader.prototype = Student....
Syed Faheem's user avatar
0 votes
1 answer
107 views

How to create a `new` constructor for a `type`

Is there a way to create a constructor for a type that aliases a native object? I currently have a defined type which should be constructed with a default value. It will be created in many places so I ...
Hand-E-Food's user avatar
  • 12.4k
0 votes
0 answers
79 views

Storybook Type 'ElementsTableProps<TabGroup>' is not assignable to type 'Partial<ElementsTableProps<TabData>>'

There are such interfaces export interface TabData {} export interface TabItem extends TabData { item_id: string; item_name: string; } export interface TabGroup extends TabData { store_id: ...
yonishepelev's user avatar

1
2 3 4 5
109