함수 객체의 표준 프로퍼티 확인

CODEDRAGON Development/JavaScript, jQuery, ...

반응형

   

함수 객체의 표준 프로퍼티 확인

   

소스 코드

function add(x, y) {

return x + y;

}

//add()함수 객체 프로퍼티 확인

console.dir(add);

   

출처: <https://github.com/10zeroone/study_javascript/blob/master/WebContent/ch04-function/21.html>

   

   

함수에 다양한 프로퍼티가 생성된 것을 확인 할 수 있습니다.

__proto__영역에서 다양한 표준 프로퍼티 함수를 확인할 수 있습니다.

   

function add(x, y) { return x + y; }

  1. argumentsnull
  2. callernull
  3. length2
  4. name"add"
  5. prototype: add
  6. constructor: function add(x, y) {
  7. __proto__: Object
  8. __proto__: function Empty() {}
  9. apply: function apply() { [native code] }
  10. argumentsnull
  11. bind: function bind() { [native code] }
  12. call: function call() { [native code] }
  13. callernull
  14. constructor: function Function() { [native code] }
  15. length0
  16. name"Empty"
  17. toString: function toString() { [native code] }
  18. __proto__: Object
  19. <function scope>
  20. <function scope>

  

   

5

add()의 프로토타입 객체는 add.prototype라는 것을 가리킴.

함수가 생성될 때 만들어지며 constructor프로퍼티 하나만 있는객체를 가리킵니다.

prototype프로퍼티가 가리키는 프로토타입 객체의 constructor프로퍼티는 자신과 연결된 함수를 가리킵니다.

함수가 생성될 때 함수 자신과 연결된 프로토타입 객체를 동시에 생성하며 서로 참조하게 됩니다.

8

add()함수 객체의 부모 역할을 하는 프로토타입 객체가 Function.prototype객체라는 것 가리킴

18

Function.prototype객체의 부모는 자바스크립트의 모든 객체의 조상격인 Object.prototype객체라는 것을 가리킴

   

   

함수객체의 prototype프로퍼티 확인

   

소스 코드

<html>

<head>

<meta charset="UTF-8">

<title>함수 객체의 표준 프로퍼티 확인</title>

<script type="text/javascript">

function add(x, y) {

return x + y;

}

//add()함수 객체 프로퍼티 확인

console.dir(add);

//add.prototype 프로퍼티 확인

console.dir(add.prototype);

//프로토타입 객체와 매핑된 함수인 add()함수를 가리키는 것을 확인할 있습니다.

document.write(add.prototype.constructor);

</script>

</head>

<body>

</body>

</html>

   

출처: <https://github.com/10zeroone/study_javascript/blob/master/WebContent/ch04-function/21.html#L6>

   

add()가 생성된 후 prototype 프로퍼티에 이함 수와 연결된 프로토타입 객체가 생성, 생성된 프로포타입 객체인 add.prototype객체는 constructor와 __proto_라는 두개의 프로퍼티를 가지는 것을 확인할 수 있습니다.

add

  1. constructor: function add(x, y) {
  2. __proto__: Object

   

add() 함수 객체와 add.prototype 프로토타입 객체의 관계 도식도

반응형

'Development > JavaScript, jQuery, ...' 카테고리의 다른 글

함수 객체의 length 프로퍼티  (0) 2014.08.01
함수 객체의 length 프로퍼티  (0) 2014.07.27
값으로 할당  (0) 2014.07.23
함수도 객체  (0) 2014.07.18
함수 호이스팅  (0) 2014.07.04