Skip to content

Instantly share code, notes, and snippets.

@brianyang
Created March 9, 2012 16:47
Show Gist options
  • Save brianyang/2007445 to your computer and use it in GitHub Desktop.
Save brianyang/2007445 to your computer and use it in GitHub Desktop.
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
@brianyang
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment