ref – https://carldanley.com/js-prototype-pattern/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// build our blueprint object var MyBluePrint = function MyBluePrintObject() { this.someFunction = function someFunction() { alert( 'some function' ); }; this.someOtherFunction = function someOtherFunction() { alert( 'some other function' ); }; this.showMyName = function showMyName() { alert( this.name ); }; }; function MyObject() { this.name = 'testing'; } MyObject.prototype = new MyBluePrint(); // example usage var testObject = new MyObject(); testObject.someFunction(); // alerts "some function" testObject.someOtherFunction(); // alerts "some other function" testObject.showMyName(); // alerts "testing" |