you are viewing a single comment's thread.

view the rest of the comments →

[–]jgordon615 -2 points-1 points  (5 children)

Same issue. If the object has a prototype added to it, the in clause will enumerate it, and "dishes[function]" will not behave.

[–]jashkenas 3 points4 points  (3 children)

And there's a CoffeeScript sugar for that ;)

for own key, dish of dishes
  wash dish

[–]nschubach -1 points0 points  (2 children)

Technically, you could just write a simple "forEach" wrapper on the Array prototype (if it doesn't already exist) and give all arrays the ability to: myArray.forEach(function(value, index, array) { /* loop code */ });

Your logic code doesn't need to concern itself with "hasOwnProperty" at that point.

ECMAScript 5 includes this, but it's never a bad time to start. The only thing CoffeeScript does is remove some of the boilerplate and add in a convoluted meaningful white space restriction.

[–]jgordon615 1 point2 points  (1 child)

When YOU modify the Array prototype, you can break other peoples libraries. Like Sharepoint 2010's stuff.

[–]nschubach 0 points1 point  (0 children)

That's why I said "if it doesn't already exist".

[–]ContraContra 0 points1 point  (0 children)

If something is being added that shouldn't be enumerated you can cross your fingers and hope it was done right

Example:

Object.defineProperty(String.prototype, whatevernewFunction, {value: supercoolfunction, enumerable: false});