Today I found some useful snippets while looking for some meaningful explanation.
Here's the one explained by someone on stackoverflow,
// constructor function function MyClass () { var privateVariable; // private member only available within the constructor fn this.privilegedMethod = function () { // it can access private members //.. }; } // A 'static method', it's just like a normal function // it has no relation with any 'MyClass' object instance MyClass.staticMethod = function () {}; MyClass.prototype.publicMethod = function () { // the 'this' keyword refers to the object instance // you can access only 'privileged' and 'public' members }; var myObj = new MyClass(); // new object instance myObj.publicMethod(); MyClass.staticMethod();
You shall read the original thread here, for a more detail similar to the above example you can find it here.
No comments:
Post a Comment