Possible Duplicate:
JavaScript function aliasing doesn't seem to work
Related jsfiddle: http://jsfiddle.net/cWCZs/1/
The following code works perfectly:
var qs = function( s ) {
return document.querySelector( s );
};
qs( 'some selector' );
But the following doesn't:
var qs = document.querySelector;
qs( 'some selector' ); // Uncaught TypeError: Illegal invocation
I don't understand why.
My confusion comes with the fact that this works:
function t() {
console.log( 'hi' );
}
var s = t;
s(); // "hi"