Assignment to method invocation result

Claude Pache claude.pache at gmail.com
Thu May 15 23:44:34 PDT 2014


Le 15 mai 2014 à 20:17, Rick Waldron <waldron.rick at gmail.com> a écrit :

> 
> 
> If the "." was on the other side?
> 
>   AccessorAssignmentOperator :
>     .= IdentifierName
> 
> 
>   var string = "  a  ";
>   string .= trim(); // would throw if no `trim` method existed for `string`
> 
>   string; // "a";
> 
>  
> Where ".=" means assign the result of "Property Accessors Runtime Semantics Evaluation" with lval and rval in appropriate positions (TBH, I'm sure I missed something in there)

There is an interesting question of precedence/associativity. Normally, for a binary operator @, the two lines are more or less the equivalent:

	a @= foo(bar).baz() + quax
	a = a @ (foo(bar).baz() + quax)

But when you write, say

	str .= replace(/_/g, ' ').trim() + '  foo'

you probably don't mean

	str = str.(replace(/_/g, ' ').trim() + ' foo')

but rather:

	str = (str.replace)(/_/g, ' ').trim() + ' foo'

	
—Claude



More information about the es-discuss mailing list