鉴于:
Number.prototype.add = methodize(add);
function methodize(func) {//a function that converts a binary function to a method
return function (x) {
//console.log(x);
console.log(this);
return func(x,this);
}
}
function add(x, y) {
return x + y;
}
console.log((3).add(4));
Run Code Online (Sandbox Code Playgroud)
(3).add(4)如果更改为最后一行会引发异常3.add(4); 否则,返回7.
演示:http://jsfiddle.net/smacky311/m3NwK/2/
为什么会发生这种情况?我读到JSON周围的括号可用于将JSON转换为对象文字.但是,在描述过程的方式中,表达式被解释为对象文字,因为{在这种情况下初始化不适用.
解释器在什么条件下确定文字是表达式?我们什么时候添加括号?