enyo 2.5.X now with Native Prototype munging for FREE!

edited July 2015 in Enyo 2.5
Before enyo 2.5.x the framework left things like native Array prototype alone.

At what point was it decided that adding methods to it, instead of the old way of making methods to use in place of the missing ones, was a great idea? And why, for the love of all that is good and decent, was it decided to just jam them on there polluting everything instead of making a little more effort?

Let me give you an example:

Chrome (that wonderful fanboi touted *modern* browser) doesn't have this method Array.prototype.find Say it isn't so. How can it be? Well it just is. So along comes enyo 2.5.x. Let's fix the world but let's be careless and lazy about it. We'll do it like this:

/** * A [polyfill]{@glossary polyfill} for platforms that don't support * [Array.find()]{@glossary Array.find}. */ Array.prototype.find = Array.prototype.find || function (fn, ctx) { for (var i=0, len=this.length >>> 0; i
That's all fine and dandy until somone accesses an array in a for loop using in. Now we get to iterate our brand new "polyfill" for free. Now I'm sure this is going to degenerate into a discussion about "you're doing it wrong". Let me say that the for ... in loop is in a legacy communications library that needs to be used in the project I'm working on. I have neither the time or the inclanation to go recode it. I didn't write it in the first place.

That being said I'll ask it again. Why wasn't a little more effort made? As a quick example:

Array.prototype.find = Array.prototype.find; if(Array.prototype.find === undefined) { Object.defineProperty(Array.prototype, 'find', { enumerable: false, value: function (fn, ctx) { for (var i=0, len=this.length >>> 0; i Note: I leave the other 4 or 5 lines necessary to patch this for ancient browsers without support for Object.defineProperty as an exercise for the reader
Were the 5 or 6 extra lines of code just too much of an undertaking? Did we forget about The Principle Of Least Astonishment or is it that we just don't care anymore? Did we stop being professional because it's "Open Source"?

A legitimate answer from those making these types of decissions would be appreciated. I am long past tired of hot patching enyo before it even loads so that I don't have to deal with stuff like this.

Comments

  • edited August 2015
    I hear and understand what you're saying here. This is something that we could do better on. We did get a pull request to address this but it was not complete as it did not have the fallbacks for IE. Which, of course, will still cause that old library to break.

    Of course, I could go on, as you said, talking about for...in used on arrays and doing it wrong but that doesn't really address the issue. I will add a task to improve our shims for the 2.6 release. If you want to submit a PR against 2.5-upkeep we can pull that in there. It needs to be backwards compatible with older browsers, though.
Sign In or Register to comment.