Created
November 30, 2011 05:10
-
-
Save dmitry/1408116 to your computer and use it in GitHub Desktop.
Javascript OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
this.OOP = function(options){ | |
this.constructor.staticVariable++; | |
this.constructor.staticMethod(); | |
var privateVariable = Math.random(); | |
function privateMethod() { | |
console.log('privateMethod:'); | |
console.log(privateVariable); | |
console.log(privateMethodStub()); | |
console.log(this.publicVariableInternal); | |
console.log(this.publicMethodInternalStub()); | |
console.log(this); | |
} | |
function privateMethodStub() { | |
console.log('publicMethodInternalStub'); | |
} | |
this.publicVariableInternal = Math.random(); | |
this.publicMethodInternal = function () { | |
console.log('publicVariableInternal:'); | |
console.log(privateVariable); | |
console.log(privateMethod.call(this)); | |
console.log(this.publicVariableInternal); | |
console.log(this.publicMethodInternalStub()); | |
console.log(this); | |
} | |
this.publicMethodInternalStub = function() { | |
console.log('publicMethodInternalStub'); | |
} | |
console.log('Options:'); | |
console.log(options); | |
console.log(this); | |
} | |
OOP.prototype.publicMethodExternal = function () { | |
console.log('publicMethodExternal:'); | |
console.log(this); | |
// console.log(privateVariable); | |
// console.log(privateMethod()); | |
console.log(this.publicVariableExternal); | |
console.log(this.publicVariableInternal); | |
console.log(this); | |
} | |
OOP.prototype.publicVariableExternal = Math.random(); | |
OOP.staticVariable = 0; | |
OOP.staticMethod = function () { | |
console.log('staticMethod:'); | |
console.log(this.staticVariable); | |
console.log(this.staticMethodStub()); | |
console.log(this); | |
} | |
OOP.staticMethodStub = function () { | |
console.log('staticMethodStub:'); | |
} | |
}).call(this); | |
oop = new OOP({test: 1}); | |
oop.publicMethodInternal(); | |
oop.publicMethodExternal(); | |
console.log(OOP.staticMethod()); | |
console.log(OOP.staticVariable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment