July 25, 2012 - TC39 Meeting Notes

Herby Vojčík herby at mailbox.sk
Sat Jul 28 06:28:51 PDT 2012

David Bruant wrote:
> Le 28/07/2012 14:37, Herby Vojčík a écrit :
>> David Bruant wrote:
>>> Le 28/07/2012 13:43, Herby Vojčík a écrit :
>>>> David Bruant wrote:
>>>>>        var a = [];
>>>>>        a.push = function(elem){
>>>>>            if(condition(elem)){
>>>>>                // do something like change the elem value then do an
>>>>> actual
>>>>> push
>>>>>                // or throw an error
>>>>>                // or just ignore this value to avoid duplicates, for
>>>>> instance
>>>>>            }
>>>>>            else{
>>>>>                Array.prototype.push.call(this, elem)
>>>>>            }
>>>>>        };
>>>>>        // use a.push (there is an implicit contract on only using
>>>>> .push to
>>>>> add elements)
>>>>> (...)
>>>>> * I could use Object.defineProperty, but the above code is definitely
>>>>> more readable and intuitive.
>>>> Well, yes. But from the philosophical PoV, imho, you should do
>>>> Object.defineProperty here, because that is what you do (your intent
>>>> is not "put a value to a's push property").
>>> My intent is "I want a custom 'push' property for this particular
>>> array", because I'm filling the array afterwards using .push calls. I
>>> don't know what I "should" be doing from a philosophical point of view,
>>> but the code written above describes my intention pretty well. If I saw
>> To be precise, [[Put]] and [[DefineProperty]] are different intents.
> I don't understand where you're getting at. Let's try to agree on some
> definitions, first:
> 1) There is my intention which I described above
> 2) there is the JS "VM" (set of primitive operations, like [[Put]] and
> [[DefineProperty]])
> 3) there is syntax which is expected to be in between, allowing to
> translate intentions (high-level descriptions) into the language
> primitive operations.

I am getting at philosophical difference between "assignment" and 
"define" and I aim at "[[Put]] is used wrong to define methods", IOW 
"[[Put]] should be used to change state (preferable only for that)".

IOW, "a.foo = 42;" is asking an object to change its state. I would 
underline _asking_ here, it's like it's a kind of ".foo=" is part of API 
of an object.

Your case of "a.push=..." is not this kind of API.

(and I know of course there is no state/behaviour distinction nor am I 
calling for one and I also know [[Put]] expands an object with new slots 
if they are not present which can be used to attack "sort of an API" 
argument; but I still hold to it*)

Whatever, if you still don't understand, don't matter. If I wasn't able 
to get the message through as of yet, I won't be probably able to do it 
by more tries anyway.

> David


* This brings me to the idea of "weak prevent-extension" which maybe 
could be useful: disallowing [[Put]] on nonexistent slots but allowing 
[[DefineProperty]]. This could be especially useful with objects (that 
is, results of [[Construct]]), so their shape is "weakly fixed" - it is 
fixed with respect to assignment, but open to low-level tweaking when 
extending with some external mixin-like behaviour etc.
But I can see that this would probably lead to just using 
[[DefineProperty]] everywhere, just in case. Which is not good.

More information about the es-discuss mailing list