Skip to content

javascrip中的分组运算符的不求值特性

LYF edited this page Aug 13, 2016 · 2 revisions

分组运算符不会进行求值。

 var GLOBAL_OBJECT = this;
 GLOBAL_OBJECT.name = 'liyanshan';
 var obj = {
    name: 'liyanfeng',
    say: function(){
       alert(this.name);
    }
 }

 console.log(GLOBAL_OBJECT);

 (obj.say)(); // liyanfeng
 (obj.say || 0)(); // liyanshan 强制求值,此时say才变成一个普通函数
Clone this wiki locally