A
Asen Bozhilov
Before few weeks ago Garret Smith payed attention for "Conditional
statement with an assignment expression":
<URL:http://groups.google.bg/group/comp.lang.javascript/msg/
9299befb874eb9a0>
He maintain theory for readable of code in statements like this one:
var x;
if (x = function(){})
{
x();
}
This is *complete* valid and *safe* approach:
| 11.13.1 Simple Assignment ( = )
| The production AssignmentExpression :
| LeftHandSideExpression = AssignmentExpression is evaluated as
follows:
| 1. Evaluate LeftHandSideExpression.
| 2. Evaluate AssignmentExpression.
| 3. Call GetValue(Result(2)).
| 4. Call PutValue(Result(1), Result(3)).
| 5. Return Result(3).
Step 4 return `undefined` independent from that is putted value or
not. `Simple Assignment` returned value from step 3.
All right but if that property for which i try to assign value has
{ReadOnly} attribute?
if (Object.prototype = function(){})
{
try {
Object.prototype();
}catch(e) {
/*Throwed from step 5 in 11.2.3 Function Calls */
window.alert(e instanceof TypeError);
}
}
statement with an assignment expression":
<URL:http://groups.google.bg/group/comp.lang.javascript/msg/
9299befb874eb9a0>
He maintain theory for readable of code in statements like this one:
var x;
if (x = function(){})
{
x();
}
This is *complete* valid and *safe* approach:
| 11.13.1 Simple Assignment ( = )
| The production AssignmentExpression :
| LeftHandSideExpression = AssignmentExpression is evaluated as
follows:
| 1. Evaluate LeftHandSideExpression.
| 2. Evaluate AssignmentExpression.
| 3. Call GetValue(Result(2)).
| 4. Call PutValue(Result(1), Result(3)).
| 5. Return Result(3).
Step 4 return `undefined` independent from that is putted value or
not. `Simple Assignment` returned value from step 3.
All right but if that property for which i try to assign value has
{ReadOnly} attribute?
if (Object.prototype = function(){})
{
try {
Object.prototype();
}catch(e) {
/*Throwed from step 5 in 11.2.3 Function Calls */
window.alert(e instanceof TypeError);
}
}