Array.prototype.func 의 개념
Array.func 대신에 Array.prototype.func 로 굳이 해야하는 이유가 뭔지 궁금해요.
Array.prototype.func = function(){
console.log('This is Array.prototype.func')
}
Array.func = function(){
console.log('This is Array.func')
}
이 둘의 차이가 뭔가요?
그차이는 Array.func은 실제로 컴퓨터가 인식할때 Array.__proto__.func와 같은 표현입니다
상속 체이닝(관계)에서 부모 유전자인 프로토타입인 Array.prototype.func 에서 참조한 값이
Array.__proto__.func이며 실제로 __proto__은 생략이가능하여 Array.func로씁니다
Array.prototype.func을 쓰는이유가 부모유전자에서 함수을 만들어서
수많은 생성된 자식 클래스에서 같은 함수를 만들지 않고 그 함수를 이용할수있는 장점입니다
즉.Array.func은 부모 유전자인 Array.prototype에서 만든 func을 사용하는것이란 의미이며
Array.prototype.func은 부모유전자에서 함수를 만드는 겁니다
Author And Source
이 문제에 관하여(Array.prototype.func 의 개념), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@no_rider/Array.func-와-Array.prototype.func-의-차이저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)