2017-03-24 1 views
-2

임이 자바 스크립트 코드의 조각을 이해할 수없는 사람이 나를 이해하는 것을 도울 수 있습니다.var some = [] [ 'forEach'] [ 'constructor'];

var some = []['forEach']['constructor']; 
+0

대괄호 표기법을 사용합니다. – Li357

+0

[[Array # forEach']의 생성자를 얻습니다 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) –

답변

1

그것은 기본적으로 Array.prototype.forEach.constructor와 같은 무엇 [].forEach.constructor과 동일합니다.

0

는 여기를 분해하는 방법 :이 코드는 유용 할 이유를 묻는 경우

[]['forEach']['constructor']; 
 

 
// Convert bracket property access notation to dot notation 
 
[].forEach.constructor; 
 

 
// `forEach` is a property of Array.prototype 
 
Array.prototype.forEach.constructor; 
 

 
// `forEach` is a function reference with a 
 
// `constructor` property, due to `Function.prototype` 
 
Function.prototype.constructor; 
 

 
// `Constructor.prototype.constructor === Constructor`, generally 
 
Function; 
 

 

 
console.log(
 
    []['forEach']['constructor'] === Function //=> true 
 
);

, 내가 아주 확실하지 않다. 아마도 난독 화.

관련 문제