Wednesday 18 June 2014

JavaScript Functional Inheritance

Taken from Douglas Crockford:

function gizmo(id) {
return {
id: id,
toString: function () {
return "gizmo " + id;
}
};
}

function hoozit(id) {
var that = gizmo(id);
this.test = function (testid) {
return testid === id;
};
return that;
}

JS Fiddle: http://jsfiddle.net/stevenhollidge/FGbX6/

No comments:

Post a Comment