jquery - How to share variables between classes in javascript -
i expanding js knowledge building custom libraries on-top of jquery/js , classes have interact between each other. coming php, there use static variables, have no idea in js. here example of want:
var = function() { this.mypublicvar = "thisshouldbeprintedfromclassb"; } a.prototype = { showmyvar : function() {alert(this.mypublicvar);} // gets triggered on direct access. } var b = function() {} b.prototype = { // have no idea how to access a.mypublicvar } anyone provide me simple tutorial or anything?
ps: have started expand js knowledge, have used js/jquery easy design purposes (using selectors , building data validators , etc.)
you can use inheritance access variable.
var = function() { this.mypublicvar = "thisshouldbeprintedfromclassb"; } a.prototype = { showmyvar : function() {alert(this.mypublicvar);} // gets triggered on direct access. } var b = function() {} b.prototype = new a(); b.prototype.print = function(){ alert(this.mypublicvar); } var b = new b(); b.print();
Comments
Post a Comment