0

How can I override the log method of the console object in order to turn this:

//objectXYZ: {prop: 1}
console.log(objectXYZ);
==> {prop: 1}

Into this:

//objectXYZ: {prop: 1}
console.log(objectXYZ);
==> objectXYZ: {prop: 1}

So I could save time and instead of typing console.log("object: ",object);, I would only type console.log(object);

Any ideas?

MagisterMundus
  • 335
  • 4
  • 18
  • A function has no way of knowing the name of the variable that you are passing to it, and at any rate, you shouldn't be trying to modify the console object. – JLRishe Mar 12 '15 at 13:58
  • Parameters passed to functions do not come along with their names. – Jim Cote Mar 12 '15 at 14:00
  • [Entirely](https://stackoverflow.com/questions/4602141/variable-name-as-a-string-in-javascript) [impossible](http://stackoverflow.com/q/9795773/1048572) in JavaScript. – Bergi Mar 12 '15 at 14:00
  • You would have to change your calling method to something like: `func({name:'objectXYZ',value:objectXYZ})` – Jim Cote Mar 12 '15 at 14:01

0 Answers0