How to access object prototype in javascript?

var f = function(); var instance = new f(); If you know name of instance class function, you can simply access prototype as: var prototype = f.prototype; prototype.someMember = someValue; If you don’t: 1) var prototype = Object.getPrototypeOf(instance); prototype.someMember = someValue; 2) or var prototype = instance.__proto__; prototype.someMember = someValue; 3) or var prototype = … Read more

Object.defineProperty in ES5?

There are several things that you can’t emulate from the ECMAScript 5 Object.create method on an ECMAScript 3 environment. As you saw, the properties argument will give you problems since in E3-based implementations there is no way to change the property attributes. The Object.defineProperty method as @Raynos mentioned, works on IE8, but partially, it can … Read more

Grasping prototypical Inheritance through pseudoclassical instantiation (JavaScript)

When using constructor functions for inheritance in JavaScript, you: Make the prototype property of the “derived” constructor an object whose prototype is the prototype property of the “base” constructor. Set the constructor property on the “derived” constructor’s prototype property to point to the “derived” constructor. Call the “base” constructor from the “derived” constructor with the … Read more

Properties of Javascript function objects

I’m not sure this will answer your question but may give you some insight. Consider the following example: var Person = (function () { var Person = function (name) { this.name = name; } Person.greet = function () { console.log(“Hello!”); } Person.prototype = { greet: function () { console.log(‘Hello, my name is ‘ + this.name); … Read more

Why use Object.prototype.hasOwnProperty.call(myObj, prop) instead of myObj.hasOwnProperty(prop)?

Is there any practical difference [between my examples]? The user may have a JavaScript object created with Object.create(null), which will have a null [[Prototype]] chain, and therefore won’t have hasOwnProperty() available on it. Using your second form would fail to work for this reason. It’s also a safer reference to Object.prototype.hasOwnProperty() (and also shorter). You … Read more

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

Quick answer: A child scope normally prototypically inherits from its parent scope, but not always. One exception to this rule is a directive with scope: { … } — this creates an “isolate” scope that does not prototypically inherit. This construct is often used when creating a “reusable component” directive. As for the nuances, scope … Read more

tech