prototype object. When object instances are created using the
new keyword in front of a function they reference all the properties and methods of that function's prototype. As such, all properties of the prototype object are also properties of that object.
Even though a function automatically comes with a prototype, a function may actually use any object as its prototype. Thus, we can mimic a classical inheritance strategy by setting the prototype of some function to an instance of some other function, its "superclass".
Function#extend([ properties ])
Function#extend is used to create an inheritance hierarchy that automatically sets up the prototype chain from one constructor function to another.
var Person = Objectextendthisname = name;return 'Hi, my name is ' + thisname + '.';;var Employee = Personextendthissupername;thistitle = title;return thissuper + " I'm an " + thistitle + '!';;var buzz = 'Buzz' 'astronaut';buzzsayHello; // Hi, my name is Buzz. I'm an astronaut!Employeeparent; // PersonEmployeeisChildOfPerson; // truePersonisParentOfEmployee; // trueEmployeeancestors; // [ Person, Object ]EmployeeisDescendantOfObject; //trueObjectisAncestorOfEmployee; // true
Under the hood
Function#inherit to setup the prototype chain.
Object.defineProperties. Please see kangax's excellent ECMAScript 5 compatibility table for information on which browsers support ES5.
$ npm install monterey
Then, in your node program use
require('monterey') to set it up.
In browsers, just include
dist/monterey.min.js using a
Please file issues on the issue tracker on GitHub.
To run the tests in node:
$ npm install $ npm test
To run the tests in Chrome:
$ npm install $ npm run test-browser