Tab Atkins Jr. wrote:
On Tue, May 29, 2012 at 10:21 AM, Brendan Eich<[email protected]> wrote:
Tab Atkins Jr. wrote:
Make monocle-mustache solely use the "obj.{foo=bar}"
syntax, so that the other one is a syntax error. There's no good
reason to give devs the other type of functionality besides
completeness, and using it will almost always be a mistake on the
dev's part, I think.
Who says obj is an Object instance delegating only to Object.prototype?
Is the "setter on Object.prototype" the only observable difference
between the two?
Not for mustache, where obj can be any object, with a deep prototype chain,
setters declared via ES5-standard syntax (no definePropert{y,ies}), or
created by an OOP library.
As Allen points out, classes will (let's hope) allow easy declaration of
deep chains too.
Beware scenario-solving in an all-or-nothing way. There's no absolute good
here, and while people may (due to Prototype's Object.extend) want = not :
in most cases, that doesn't mean : is unnecessary.
I'm not making the assumption that "obj" in the examples is
necessarily an Object with Object.prototype. It's irrelevant to the
two points I'm trying to make:
1. The use-case for mustache is to replace current code that does a
lot of property-assigning statements with a more concise expression.
2. Devs will generally be surprised by [[DefineOwnProperty]] behavior,
since it's not observably different from [[Put]] in current code
except in some degenerate cases that aren't seen in non-adversarial
scenarios.
Fair points so far, and why Dave Herman proposed using = and ;
separation for a "fluent style" chaining extension:
obj.{
prop1 = val1;
...
propN = valN;
};
Dave's proposal (which I can't find atm, it may be in a gist) also
supports method calling with obj as |this|, a la JQuery chaining style
but without requiring the methods to all return |this|.
I would also assert that there's not a strong use-case for giving
[[DefineOwnProperty]] substantially more concise syntax. (I'd agree
with a somewhat terser API than the current Object.defineProperties(),
but I don't think it needs actual syntax support.)
The data theft attack may mutate away from JSON and toward pure JS if
mustache becomes popular enough under any syntax that uses [[Put]]. Yes,
we could say "defensive coders must use Object.definePropert{y,ies}" but
that won't have much effect.
When you do have a deep prototype chain, with details possibly buried
deep in code that you don't want to look at, how often do you actually
want to completely replace a given property?
Shadowing has its uses too. When you're making a work-alike but with
AOP-ish advice, e.g. Various libraries support this kind of thing. But
let's not ask what are essentially rhetorical questions. Here's what I
think:
For new objects you create locally in a small-world codebase, : for
define works as well as = for assign.
For the DOM, esp. the CSSOM, = is the only way.
I'm using = and : abstractly here, not pushing them as final syntax.
Therefore I believe that if we can't agree on = and : both having
support in mustache, we should use different-enough looking syntax, a la
Dave's misplaced gist for fluent style, and not get stuck here and end
up with nothing.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss