나는 연산자를 사용하여 원시 객체를 확장하려고 시도했다. 그것은 작동합니다. 생각할 수있는 부작용이 있습니까?+/- 등으로 오브젝트를 확장 할 수 있습니까?
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!
내가 그 아무것도 영향을 볼 수 없습니다 또한 this jsfiddle
부정적인 영향은 생각할 수 없지만 실제로는 코드 작성/읽기가 쉬워 진다고 스스로에게 묻습니다. 나는 그것이 당신의 경우에 정반대의 것이라고 주장 할 것입니다. – Alex