Created
October 30, 2015 14:50
-
-
Save NoMan2000/44d746d3e964832a021e to your computer and use it in GitHub Desktop.
JavaScript create a virtual object
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 Foo = function(){ | |
this.par = 3; | |
this.sub = new(function(t){ //using virtual function to create sub object and pass parent object via 't' | |
this.p = t; | |
this.subFunction = function(){ | |
alert(this.p.par); | |
} | |
})(this); | |
} | |
var myObj = new Foo(); | |
myObj.sub.subFunction() // will popup 3; | |
myObj.par = 5; | |
myObj.sub.subFunction() // will popup 5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment