質問

var foo = {}; 
document.body.innerHTML = console.log = location.hash = 'Hi ' + '<br>  ' + foo.bar + '<br>  ' + foo.baz; 

setTimeout(function()
           {
  foo.baz = foo["bar"] = []; 
  foo.bar.push(new Date); 
  foo.baz.push(new Date); 
  document.body.innerHTML = console.log = location.hash = 'Hi ' + '<br>  ' + foo.bar + '<br>  ' + foo.baz}, 
           5000);

役に立ちましたか?

解決

Since you set node.bar equal to false, (node.foo && node.bar) will evaluate to false whether the properties are attached or not. Rather than checking if those properties are true, you should check whether they are undefined:

if (typeof node.foo !== 'undefined' && typeof node.bar !== 'undefined') 
{ 
  ...
} 
else 
{
  ...
}

他のヒント

Looks like it may be implementation dependent:

The object that may be created in step 1 is not accessible outside of the above method. An implementation might choose to avoid the actual creation of the object. The only situation where such an actual property access that uses this internal method can have visible effect is when it invokes an accessor function.

So instead of accessing the property, stringify and pass by value.

References

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top