Created
March 6, 2012 01:56
-
-
Save Armen138/1982840 to your computer and use it in GitHub Desktop.
Structured Javascript Example
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
var AClass = function () { | |
"use strict"; | |
//Private variables and functions | |
var self = this, | |
priv1 = 66, | |
priv2 = 2, | |
privMethod = function () { | |
return priv2; | |
}, | |
privMethod2 = function () { | |
return priv1; | |
}; | |
//Public variables and functions | |
this.pub1 = 22; | |
this.pub2 = 33; | |
this.pubMethod = function (x) { | |
return privMethod() + this.pub1 + x; | |
}; | |
this.pubMethod2 = function () { | |
return privMethod2 + this.pub2; | |
}; | |
//Constructor body | |
if(priv1 < 44) { | |
priv1 += priv2; | |
} | |
}; | |
var BClass = function () { | |
"use strict"; | |
//Inherit from Aclass | |
AClass.apply(this); | |
//Private variables and functions | |
var self = this, | |
$pubMethod = this.pubMethod.bind(this), | |
priv1 = 33; | |
//Public variables and functions | |
this.pubMethod = function () { | |
return $pubMethod(3) + priv1; | |
}; | |
}; | |
var bClass = new BClass(); | |
console.log(bClass.pubMethod()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment