Ajax Blogs - 324 days ago Posted by bluray

Are you ever sick of seeing Object get printed out when you try to output a variable to your console.
Oliver Steele talks about Self Printing JavaScript Literals where you can clean that up with a toString:
PLAIN TEXT
JAVASCRIPT:


function makeLiteral(name) {return {toString:function(){return name}}}
var L1 = makeLiteral("L1");
var L2 = makeLiteral("L2");
L1
//>>> L1<

Log in to comment or register here.

Comments

Who voted for this story

Get your Certification Practice Tests and Assessments at MeasureUp! Prepare for Certification with MeasureUp!