Created
March 9, 2012 16:47
-
-
Save brianyang/2007445 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 objRef = function(val){ | |
console.log(val) // will return passed var | |
var val = 'baz' // redefining the value of this var within this block | |
this.destroy = function(){ // defining an object of objRef that can be called using objRef.destroy() | |
assert(objRef) // this will not work because the compiler has no knowledge of objRef in this scope | |
} | |
} | |
var foo = 'bar' // define a test var | |
objRef(foo) // pass our var to the object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there is no way to redefine the value of an object within itself, variable definition must be done in the scope the variable is defined