Microsoft did it once again ! - tried to pass an object to a function but didn't work out. So this is the work around I cooked up ... sleazy eh !

was trying this:

<li onclick="myFunction( { listObject:this, customOption: 1 } )" > List text bla bla </li>

Now this above code worked in FireFox flawless ! but IE started giving me problems. More specifically, I wanted to highlight the li item and call another script via AJAX for which I needed the value for my customOption. But hell no ! Professor IE says the world goes round my way and the WebStandardsProject would keeping on feeling my shoe in their backside ! BLEKH ! - so I cooked up this workaround. Its fail safe:

<li onclick="this.prototype.customOption = 1; myFunction(this);">List text bla bla</li>

Now this is pretty cool. You can add any property or even a function using the "prototype" global function. It would really help if you read a bit more about it here these netscape guys were the creators of the JavaScript in the first place and this handbook here is pretty cool.

There is a downside to this workaround however, imagine there are many options, your code will SUCK! - I hope these evils are undone in IE 7 and other versions to come. However I'm still wondering why does IE not take "{ propertyName1: value, propertyName2: value, ..... }" model as arguments properly ... anybody out there has a clue let me know ! - I'd really appreciate your comments.


No Responses to “objects as arguments fail in IE”  

  1. No Comments

Leave a Reply