All Questions

108
votes
2answers
11981 views

Prototypical inheritance - writing up

So I have these 2 examples, from javascript.info: Example 1: var animal = { eat: function() { alert( "I'm full" ) this.full = true } } var rabbit = { jump: function() { /* something *...
926
votes
3answers
137671 views

What are the nuances of scope prototypal / prototypical inheritance in AngularJS?

The API Reference Scope page says: A scope can inherit from a parent scope. The Developer Guide Scope page says: A scope (prototypically) inherits properties from its parent scope. So, doe...
679
votes
14answers
97847 views

Use of 'prototype' vs. 'this' in JavaScript?

What's the difference between var A = function () { this.x = function () { //do something }; }; and var A = function () { }; A.prototype.x = function () { //do something };
39
votes
6answers
6794 views

What is the reason to use the 'new' keyword at Derived.prototype = new Base

What does the following code do: WeatherWidget.prototype = new Widget; where Widget is a constructor, and I want to extend the Widget 'class' with a new function WeatherWidget. What is the new key...
538
votes
20answers
106635 views

__proto__ VS. prototype in JavaScript

This figure again shows that every object has a prototype. Constructor function Foo also has its own __proto__ which is Function.prototype, and which in turn also references via its __proto__ p...
79
votes
6answers
17394 views

Why is extending native objects a bad practice?

Every JS opinion leader says that extending the native objects is a bad practice. But why? Do we get a perfomance hit? Do they fear that somebody does it "the wrong way", and adds enumerable types to ...
108
votes
4answers
17291 views

Why are Perl 5's function prototypes bad?

In another Stack Overflow question Leon Timmermans asserted: I would advice you not to use prototypes. They have their uses, but not for most cases and definitely not in this one. Why might...
113
votes
5answers
16975 views

What it the significance of the Javascript constructor property?

Trying to bend by head around Javascript's take on OO...and, like many others, running into confusion about the constructor property. In particular, the significance of the constructor property, as I ...
220
votes
4answers
69355 views

Advantages of using prototype, vs defining methods straight in the constructor?

I am wondering if there are any advantages of using any of these over the other, and which way should I go? Constructor approach: var Class = function () { this.calc = function (a, b) { ...
19
votes
3answers
2937 views

Javascript object members that are prototyped as arrays become shared by all class instances

Has anyone noticed this behavior before? This really threw me off... I would have expected prototyped arrays to be private to each class instance rather than shared between all class instances. Can s...

Previous Next