oop - Is there a way to inherit this javascript pattern? -
i have javascript pattern , i'd inheritance. can tell me how it?
var namespace = { app: {} }; namespace.app.main = (function($) { var main = function(options) { var _private; _private = function() { console.log('this private function'); }; return { public: function() { console.log('this public function'); } }; }; return function(options) { return new main(options); }; })(jquery);
what i'd have inherits functions object like
var obj = new namespace.app.newmain(); obj.public();
thanks advice {jim}
you need use prototype
of function object in order proper inheritance.
function child(){ ... } child.prototype = new namespace.app.newmain(); var inst = new child(); inst.public();
Comments
Post a Comment