I have been trying some fundamentals in javascript and here is what I observed.
I wrote a prototype modification method for Function object
Function.prototype.method = function(name, func)
{
this.prototype[name] = func;
return this;
}
function pirates(value)
{
console.log("I just throw away the value!!" + value);
}
pirates.method("my_skill", function(){
console.log("Pirate skills");
});
new_pirate = new pirates(1234);
//SUCCESS
new_pirate.my_skill(); //prints "Pirate skills"
var someCrappyVariable = function(){
return function()
{
console.log("I am going to just sit and do nothing. Really!");
}
}();
**//Throws error. WHY???????? This was assigned a function, so ideally prototype should work on this too? Shouldn't it?**
someCrappyVariable.method("crappyFunction", function(){
console.log("am I doomed?");
});
Why does last assignment throws an error that someCrappyVariable is not a function, when it was assigned a function reference earlier? I am confused.
Cheers
crappyFunctionmethod