javascript - Why can't console.log be called using .call() -
the below code returns pop-up window 'hello'.
alert.call(this, 'hello'); but below code returns error "typeerror: illegal invocation".
console.log.call(this, 'hello'); what difference in implements of alert , console.log?
alert global method (window.alert). if call alert.call(this), this window object.
because log method in console object, expects this console object itself, still calling this(window), error.
running console.log.call(console, 'test') work fine.
Comments
Post a Comment