Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Comment Re:I love the autopointerage & hate the scope (Score 1) 439

> if( !Array.push )
> Array.prototype.push = function( item ){ ... }

Yes, this sounds nice, but it's a large pitfall too. It's very tempting to start extending 'basic datatypes' with all kinds of stuff, which can result in awful clashes with other libraries that do the same. Ruby on Rails' 'Prototype' library is a good example of how _not_ to use this.

> someObject.onclick = function(){ myFunction( this.someAttribute ) }

Horrible indeed. The idea of allowing to call a method with a different 'this' is already scary, and useful only for nasty hacks, but I think actually using this feature in very commonly used functionality* was a big mistake (perhaps not so obvious when 'object oriented' programming (yes, the prototype stuff, i know it's not strictly oo) wasn't very common, but nowadays it's one of the first walls JS developers bump into).

> function array_push( arr , item )
> arr[arr.length] = item;

Nothing new here I think... There's more (intepreted) languages that can do this. And most other languages actually _do_ implement push() (or something similar) on all platforms. ;)

> someObject.onclick = myFunction

Nothing new here either. Try Python for instance, which is a lot more dynamic than JavaScript... :)

Yes, I understand that JS has certain very nice features when you're used to more static ones like C or Java or whatnot, but I think compared to certain others (note that most of JS' features are in some way stolen from other languages) its awful implementation, lack of basic functionality (no String.strip() while there is a String.blink()?!?), sheer unintuitiveness (it's for instance not at all clear what notation to use for 'OO', there's a billion ways to define objects and prototypes and such, and the differences are subtle) and strange quirks (like the nested scopes example you mention, but there's plenty more examples) are reason enough to still see it as 'necessary evil' rather than 'an enlightening experience'... ;)

(Do note that I'm a bit biased, as I'm (not deeply, but a bit) involved in the PyPy project, which works on (among a lot of other things) a Python to JavaScript compiler... ;)

* most notably event handlers: when registering an event handler in certain ways 'this' points to the event, or the element on which the event is defined, or something, and not to the object, making that you need to use closures to actually have a reference to the object the method is defined on, from the method :|

Slashdot Top Deals

The key elements in human thinking are not numbers but labels of fuzzy sets. -- L. Zadeh

Working...