javascript - how to pass an array elements to log set of parameters in one line -



javascript - how to pass an array elements to log set of parameters in one line -

once upon time advertisement assignment task on 1 of interviews hasn't been giving me sleep since:

need log arguments-object in console in 1 line date in end. objects(to able inspect those), not string( array prototype.join() - not solution in case)

a fail attempt(out of function scope):

var fn = function () { var arr = array.prototype.slice.call(arguments); arr.push(new date().tojson()); function.prototype.call.apply( console.log, arr ); } fn( 1, 'a', [2, 3], {a:1} );

logs:

uncaught typeerror: illegal invocation

any ideas?

use logging

function.prototype.call.apply( console.log.bind(console), arr );

instead of

function.prototype.call.apply( console.log, arr );

it work.

javascript arguments prototype

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -