xtopolis Posted November 13, 2008 Share Posted November 13, 2008 What is happening in the "name = { 'for..." statement? What is happening here in the return statement? function attr( elem, name, value ){ if( !name || name.constructor != String ) return ''; name = { 'for': 'htmlFor', 'class': 'className' }[name] || name; if( typeof value != 'undefined' ) { elem[name] = value; if( elem.setAttribute ){ elem.setAttribute(name,value); } } return elem[name] || elem.getAttribute(name) || '';//here } A detailed explanation would be helpful, thanks. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 13, 2008 Share Posted November 13, 2008 It's simply a JavaScript Object. I'm not sure what the [name] || name is for though. But you declare objects in JavaScript like so: var myObject = { foo: 'bar', //A property init: function(){ //A method alert(this.foo); } }; myObject.init(); Quote Link to comment Share on other sites More sharing options...
xtopolis Posted November 13, 2008 Author Share Posted November 13, 2008 Oh, duh, I should have realized it was an object just with different formatting. >.< thanks As for the expression || expression;.. I'm assuming it's casting to whichever is true, or the last expression if false, but I'm not certain. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 13, 2008 Share Posted November 13, 2008 Yeah I don't no exactly. It just looks weird and out of place. Oh well, if its working then it should be fine. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted November 13, 2008 Author Share Posted November 13, 2008 Oh well, if its working then it should be fine. Ha, not good enough for me >.< I need to know what it is, and why ~.~ Perhaps Nightslyr will stumble upon this topic and if he/she is not angry at me, enlighten me. Thanks for the help thus far. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.