function myFunction(messager) {
this.message = messager;
}
new myFunction("Hello");
document.write(myFunction.message);
function myFunction(messager) { this.message = messager; } new myFunction(Hello); document.write(myFunction.message);
Share
You were trying to reference a member of the function object itself, which is totally incorrect.
When using
thisin conjunction with thenewkeyword,thiswill refer to the object instance which is implicitly returned from the constructor function.This code should work:
You can also use the
prototypemember to augment member functions and variables onto the created objects: