I'v는 기본 객체에 배열의 프로토 타입을 적용하는 두 가지 건너 목적 :[] .slice 또는 Array.prototype.slice
type = Object.prototype.toString.call(obj);
type = {}.toString.call(obj);
간단한 테스트 :
function fn() {
console.log(
Array.prototype.slice.call(arguments),
[].slice.call(arguments),
Object.prototype.toString.call(arguments),
{}.toString.call(arguments)
);
}
fn(0,1);
바이올린 : http://jsfiddle.net/PhdmN/
그들은 저와 동일하게 보입니다. 첫 번째 구문은 더 자주 사용되지만 두 번째 구문은 확실히 더 짧습니다. 더 짧은 구문을 사용할 때 단점이 있습니까?
두 번째 구문은 불필요하게 새로운 개체를 만듭니다. –
@ Dan.. 정답이므로 답변으로 게시해야합니다. ;) – Lucero