Possible Duplicate:
Create shortcut to console.log()
In javascript we can easy assign functions to variables, eg :
a = function(){ alert("hello world");}
b = a;
Now both a and b can be interchangeably used to generate an alert message.
But when creating a cross browser console wrapper, I noticed a very peculiar behaviour in chrome :
x = console.log
now when I use :
x("hello world")
I get :
TypeError : Illegal invocation
However the above example works perfectly fine in firefox.
Is this some sort of security related issue with chrome or something altogether different. On a sidenote, is there a way I can get a function which generates an output to browser console with the line number where the function was called ?
Method assignments like in your example lose their
thiscontext.Try…