Parse JSON String into a Particular Object Prototype in JavaScript

I know how to parse a JSON String and turn it into a JavaScript Object. You can use JSON.parse() in modern browsers (and IE9+). That’s great, but how can I take that JavaScript Object and turn it into a particular JavaScript Object (i.e. with a certain prototype)? For example, suppose you have: function Foo() { … Read more

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

This question already has answers here: Use of ‘prototype’ vs. ‘this’ in JavaScript? (15 answers) Closed 9 years ago. 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) { … Read more

Understanding the difference between Object.create() and new SomeFunction()

I recently stumbled upon the Object.create() method in JavaScript, and am trying to deduce how it is different from creating a new instance of an object with new SomeFunction(), and when you would want to use one over the other. Consider the following example: var test = { val: 1, func: function() { return this.val; … Read more

__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__ property again to the Object.prototype. Thus, repeat, Foo.prototype is just an explicit property of Foo which refers to the prototype of b and c objects. … Read more

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, does a child scope always prototypically inherit from its parent scope? Are there exceptions? When it does inherit, is it always normal JavaScript prototypal inheritance? … Read more