我试着用操作符来扩展本地对象。有用。会有可以想到的副作用吗?我可以使用+/-等扩展对象吗?
Number.prototype['+++'] = function(n){
return this + (2*n);
};
String.prototype['+'] = function(){
return this += [].slice.call(arguments).join('');
}
alert(10['+++'](10)); //=> 30
alert('hello '['+']('world ','and ','see you later!'));
//=> hello world and see you later!
我想不出任何负面影响,但是我会问自己,这是否确实使代码更容易编写/读取?我认为你的情况恰恰相反。 – Alex 2011-04-06 19:52:42