Should the "length" property of bound functions be configurable
The uncurryThis
metafunction, given as example in 1, needs to correct the length of a function produced by bind
. Simplified version:
uncurryThis = f => Function.protytpe.call.bind(f) // uncurryThis(f).length == 1 instead of f.length + 1
So, yes, bind
should produce functions with mutable length.
Allen probably could use a bug on file at bugs.ecmascript.org -- anyone?
I think a function's "name" and "length" should have similar attributes. It seems we have legacy saying that "name" should be writable. This may be unfortunate, but consistency between the two is the more important principle.
Le 30 août 2013 à 18:54, "Mark S. Miller" <erights at google.com> a écrit :
It seems we have legacy saying that "name" should be writable.
Really? Just tried in the console of the latest stable versions of Firefox, Safari, Chrome and IE:
Object.getOwnPropertyDescriptor(function() {}, 'name')
Firefox, Safari and Chrome: {value: "", writable: false, enumerable: false, configurable: false}
IE: undefined
Cool. In that case we have more freedom. In any case, we should give both of these the same attributes.
Filed bug: ecmascript#1868
Part of the function name proposal submitted would make "name" writable but not configurable, which is the inverse of the current spec for "length" being configurable but not writable. Seems there needs to be some discussion on what attributes should be where.
Mark and I discussed this privately a while back. We would rather use the same attribute pair for both. Is non-writable configurable ok? I argued that for name it is onerous to require Object.defineProperty calls, e.g., from Cappuccino when compiling Objective-J into JS, to fix up every function's name to tell its Obj-J pathname. But you wrote the name proposal -- you should weigh in and even call this shot!
The thing that worries me about configurability is that it allows something to become an accessor. I was following the path of "prototype" when deciding on non-configurability for "name". Essentially: preventing arbitrary code from executing when accessing this thing.
I'm not married to this restriction, I just wanted to following real world implementations as closely as possible. If implementors have no issue then I don't. But figured every difference between existing implementations and the spec was an additional barrier to my idea becoming realistic reality.
On Fri, Aug 30, 2013 at 2:39 PM, Brandon Benvie <bbenvie at mozilla.com> wrote:
Part of the function name proposal submitted would make "name" writable but not configurable, which is the inverse of the current spec for "length" being configurable but not writable. Seems there needs to be some discussion on what attributes should be where.
Relevant: rwaldron/tc39-notes/blob/master/es6/2013-07/july-25.md#513
The latest spec revision makes the function "length" property configurable (section 8.3.16.6). Function.prototype.bind (15.3.3.5) still produces functions with non-configurable "length", however. I think this may be an oversight, but I'm not sure.