prototype 확인
객체 리터럴 방식으로 생성된 객체는 Object.prototype 객체가 프로토타입 객체가 된다는 것을 확인 할 수 있습니다.
소스 코드
<script type="text/javascript">
var student = {
name: 'student',
age: 30
};
console.log(student.toString());
console.dir(student);
</script>
</head>
<body>
</body>
|
출력결과
크롬 브라우저의 출력결과
Object
- age: 30
- name: "student"
- __proto__: Object
- __defineGetter__: function __defineGetter__() { [native code] }
- __defineSetter__: function __defineSetter__() { [native code] }
- __lookupGetter__: function __lookupGetter__() { [native code] }
- __lookupSetter__: function __lookupSetter__() { [native code] }
- constructor: function Object() { [native code] }
- hasOwnProperty: function hasOwnProperty() { [native code] }
- isPrototypeOf: function isPrototypeOf() { [native code] }
- propertyIsEnumerable: function propertyIsEnumerable() { [native code] }
- toLocaleString: function toLocaleString() { [native code] }
- toString: function toString() { [native code] }
- valueOf: function valueOf() { [native code] }
- get __proto__: function __proto__() { [native code] }
- set __proto__: function __proto__() { [native code] }
|
3라인 | 객체 리터럴 방식으로 생성된 객체는 Object.prototype 객체가 프로토타입 객체가 된다는 것을 확인 할 수 있습니다. |
9~14
라인 | toString()외에 hasOwnProperty(), valueOf90등과 같은 자신의 프로토타입인 Object.prototype객체에 포함된 다양한 메소드를 마치 자신의 프로퍼티인 것 처럼 상속받아 사용할 수 있습니다. |
student객체와 Object.prototype객체와의 도식도
ECMAScript 명세서- 세부 참조
ECMAScript 명세서-8.6.2 Object Internal Properties and Methods
자바스크립트의 모든 객체는 자시의 프로토타입을 가리키는 Prototype라는 숨겨진 프로퍼티를 가집니다.
Object,prototype 객체가 포함하고 있는 메서드 확인하기
ECMAScript 명세서- 15.2.4 Properties of the Object Prototype Object
ECMAScript 참조
http://codedragon.tistory.com/46
댓글을 달아 주세요