-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudoClassicalNotes.js
27 lines (20 loc) · 979 Bytes
/
pseudoClassicalNotes.js
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
// 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
// See (http://blog.anselmbradford.com/2009/04/09/object-oriented-javascript-tip-creating-static-methods-instance-methods/)
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 produced here!
myObj.publicMethod();
MyClass.staticMethod();
// From http://stackoverflow.com/questions/1635116/javascript-class-method-vs-class-prototype-method
// See also: https://developers.google.com/speed/articles/optimizing-javascript for method efficiency.