joi, 13 august 2009

Javascript gotcha


Usually the style you organize code is just that A MATTER OF STYLE, in javascript however it’s not.




If by any chance you end up writing the following code:



 



var display = function() {
this.x = 10;
return
{
alert: function(message) {
window.alert(message);
}
}
}


you might be in for a surprise but it won’t return anything because by default the javascript interpreter inserts ; after every line that doesn’t already contain it or }.



Instead you should write:



var display = function() {
this.x = 10;
return {
alert: function(message) {
window.alert(message);
}
}
}


More interesting notes you can find in the next video:






Hope you enjoyed this I sure did :D.


Niciun comentariu: