2020. 06. 13
Jaewoo KIM
Function ๊ตฌ๋ถ
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var person = new Persion('Jaewoo KIM')
person.getName();
1. function Person(name) {...}
2. Person.prototype.getName = function() {}
3. var person = new Person('Jaewoo KIM')
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var obj = new Person('Jaewoo KIM')
log(obj.name);
log(obj.getName());
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var obj = new Person('Jaewoo KIM')
new ์ฐ์ฐ์๊ฐ ์ธ์คํด์ค๋ฅผ ์์ฑํ๋ ๊ฒ์ผ๋ก ์๊ฐํ ์ ์์ง๋ง ์ค์ ๋ก function์ [[Construct]]๊ฐ ์ธ์คํด์ค๋ฅผ ์์ฑ
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var obj = new Person('Jaewoo KIM')
Person ์ธ์คํด์ค: {
name: 'Jaewoo KIM'
__proto__ = {
constructor: Person,
getName: fuction() {},
__proto__: Object
}
}
Person fuction ์ค๋ธ์ ํธ: {
prototype: {
constructor: Person
}
}
var Person = function(){};
var result =
Person === Person.prototype.constructor;
log(result); // true
var obj = new Person();
log(Person === obj.contructor) // true
log(typeof Person) // function
log(typeof obj) // object
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
function Point(name) {
Person.call(this, name);
}
Point.prototype =
Object.create(Person.prototype, {});
var obj = new Point('Jaewoo KIM')
log(obj.getName())
class Person {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}
class Point extends Person {
constructor(name) {
super(name)
}
}
const obj = new Point('Jaewoo KIM')
log(obj.getName())
function Person() {};
Person.prototype = {
constructor: Person,
setName: function() {}
}
var obj = new Person();
log(obj.constructor);
// function Person() {}
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var obj = new Person('Jaewoo KIM');
obj.getName();
obj: {
name: 'Jaewoo KIM'
__proto__ = {
constructor: Person,
getName: fuction() {},
__proto__: Object
}
}
function Person() {
log("1:". this.name)
};
Person.prototype.getName = function() {
this.setName();
log('2:'. this.name)
}
Person.prototype.setName = function() {
this.name = "Jaewoo KIM"
}
var obj = new Person('Jaewoo KIM');
obj.getName();
function Person(name) {
this.name = name;
};
Person.prototype.getName = function() {
return this.name;
}
var obj = new Person('Jaewoo KIM');
log(obj.getName()); // Jaewoo KIM
log(Person.prototype.getName()) // undefined
function Person() {
this.name = 'Jaewoo KIM';
};
var obj = new Person();
log(obj.getName); // undefined
Person.prototype.getName = function() {
return this.name
}
var result = obj.getName()
log(result) // Jaewoo KIM
obj ์ธ์คํด์ค = {
name: 'Jaewoo KIM',
getName: function() {},
__proto__: {
getName: fuction() {}
}
}
function Person(name) {
this.name = name;
};
Person.prototype.getName = function() {
return 'Jaewoo KIM'
}
var obj = new Person('sat10am');
obj.getName = function () {
return this.name
}
log(obj.getName());
obj ์ธ์คํด์ค = {
name: 'sat10am',
getName: function() {},
__proto__: {
getName: fuction() {}
}
}
๋