I need to create simple reusable javascript object publishing several methods and parameterized constructor. After reading through several ‘OOP in JavaScript’ guides I’m sitting here with an empty head. How on the Earth can I do this?
Here my last non-working code:
SomeClass = function(id) { this._id = id; } (function() { function intFun() { return this._id; } SomeClass.prototype.extFun = function() { return incFun(); } })();
All vars are private:
Use
THISwithin private methods sincethiswon’t equal what you might expect.