One of the many fascinating things about JavaScript is that functions are actually objects, and they can be constructed a number of ways, one of which is using its constructor directly:
var func = new Function( "arg1" , "arg2" , "arg3" , "function_body" );
Considering that it is a javascript object, I assume that I could attach a property to the object:
func.propertyA = "whatever I want this to be";
So with that in consideration, how would I reference the property within the function?
Like this for clarity (this doesn't work):
var func = new Function( "arg1" , "arg2" , "arg3" , "alert( func.propertyA );" );
func.propertyA = "hello world";
func();
This is supposed to alert "hello world."
When you run this script in JSFiddle, you get an error in the console instead saying that "func" is undefined
.