prototype-programming Questions

4

Solved

First off, this question is not "what does the constructor property do?" - There's plenty of good documentation on exactly what it is and how it works: It's a reference to the function th...
Holbrooke asked 10/11, 2011 at 1:8

4

I've read a ton of materials about prototypes and understand inheritance in general. However, this is one thing that is bugging me and I cannot figure it out. On dmitrysoshnikov.com there is a simp...
Lotte asked 7/12, 2020 at 12:16

10

Solved

function Gadget(name, color) { this.name = name; this.color = color; } Gadget.prototype.rating = 3 var newtoy = new Gadget("webcam", "black") newtoy.constructor.prototype.constructor.prototype...
Ungual asked 16/3, 2009 at 14:55

4

Solved

I have some object, say son, which I'd like to inherit from another object father. Of course I can make a constructor function for father, like Father = function() { this.firstProperty = someVal...
Neopythagoreanism asked 10/8, 2010 at 18:57

20

Solved

I have something like this: $scope.traveler = [ { description: 'Senior', Amount: 50}, { description: 'Senior', Amount: 50}, { description: 'Adult', Amount: 75}, { description: 'Child', Amount: ...
Endo asked 23/4, 2014 at 14:47

4

Solved

In JavaScript, every object is at the same time an instance and a class. To do inheritance, you can use any object instance as a prototype. In Python, C++, etc.. there are classes, and instances, ...
Brecher asked 3/5, 2009 at 1:39

8

Solved

One of the major advantages with Javascript is said to be that it is a prototype based language. But what does it mean that Javascript is prototype based, and why is that an advantage?
Nerva asked 9/10, 2008 at 7:22

5

Solved

I noticed that every tutorial on how to do JavaScript inheritance does this: SubClass.prototype = new SuperClass(); But this will create a single instance of the super class and share it among a...
Kathlyn asked 5/1, 2012 at 0:39

4

Solved

In JavaScript we can assign properties to a function's prototype or set its prototype object directly: var MyClass = function() { }; // The "property" form... MyClass.prototype.foo = function() {...
Inotropic asked 6/6, 2011 at 18:43

5

Solved

What is the difference between the following two declarations? Class.method = function () { /* code */ } Class.prototype.method = function () { /* code using this.values */ } Is it okay to think...
Claudineclaudio asked 28/10, 2009 at 3:59

6

Solved

I often see this pattern to define javascript objects function Person(name) { this.name = name; } Person.prototype.describe = function () { return "Person called "+this.name; }; And in this ar...

3

Solved

It seems like there is a difference here... Let's say we have function MyConstructor() {} MyConstructor's [[Prototype]] is Function.prototype, not MyConstructor.prototype. In other (non-standard...
Arbitress asked 26/2, 2012 at 9:15

6

Solved

I am new to JavaScript OOP. Can you please explain the difference between the following blocks of code? I tested and both blocks work. What's the best practice and why? First block: function ...
Tomasatomasina asked 21/5, 2009 at 12:0

3

Solved

I'm on my journey to learn Object-Oriented Programming in Javascript. I got this video lession from here http://www.objectplayground.com/ which I understood quite a bit the prototypal method over c...
Coreligionist asked 26/1, 2017 at 21:10

6

Solved

You know Javascript is a prototype-based programming language . I have read some books about Javascript and its prototypal inheritance concept but: "If you can't explain it to a six-year old, you...

3

Solved

I am new to JavaScript, and trying to understand how i should write classes (my background in 'regular' OO languages, such as java and c++). I understand that i have two options: If i want my cl...
Seville asked 13/5, 2011 at 15:13

2

Solved

Say I have this code: Boolean.prototype.toString = function toString() { return this.valueOf() ? '1' : '0'; }; var object = { true: 'true', false: 'false', 1: '1', 0: '0' }; ...
Afroasian asked 6/6, 2016 at 13:55

1

Solved

I understand that my question is a little bit biased, but I am very new in Javascript and prototypes, and I read about it, but I don't really understand how to apply that techniques to my practical...

4

Solved

Using pure JavaScript to do inheritance, this is what I usually do: function A() {} A.prototype.run = function () {}; function B() {} B.prototype = new A; B.prototype.constructor = B; Since the...
Mindymine asked 23/9, 2011 at 18:44

1

Solved

I am looking at the code to find out whether an object is an array on not, and I came across this answer. The code is working fine, but I am not able to understand how it is performing a compariso...
Magog asked 10/1, 2016 at 13:23

4

Solved

// Base class var Base = function() { this._value = 'base'; }; Base.prototype = { constructor: Base, // By function getValue: function() { return this._value; }, // By getter get value() { ...

8

Solved

Is there a JavaScript pattern which mimics "Protected" object properties like what you see in languages like C++ ?? Basically, I'd like to create an Object A which has a number of "protected" obje...
Heritable asked 7/11, 2011 at 23:32

2

Solved

Today, I saw a JavaScript pattern I have never seen in my whole life. I cannot tell the purpose of using this pattern. It seems wrong to me, but I want to be a little conservative. It might be some...
Webster asked 19/8, 2011 at 0:4

1

Solved

In Javascript, any "function object" has a prototype > F = function() {} F() > F.prototype F {} But "object" or "instance" doesn't have a prototype > o = {} Object {} > o.prototype ...

4

Solved

How can i do something like this: var a = [1,2,3,4]; a.map(Date.constructor); This code throws an Error on Google V8: SyntaxError: Unexpected number I'am also tried: a.map(Date.constru...

© 2022 - 2024 — McMap. All rights reserved.