Object assign - amorfati0310/javascript-vm GitHub Wiki
Object assign๋ฉ์๋ ์ ๋ฆฌ๊ฐ ์ ๋์ด ์๋ Page
- Constructor์์ ์ฌ์ฉ
Class Point {
constructor(x,y){
this.x = x;
this.y = y;
}
}
class Point {
constructor(x, y) {
Object.assign(this, { x, y });
}
}
์ด๋ฐ ๋ถ๋ถ์ constructor(Object.assign(this, {x,y})๋ก ํ ๋นํ ์ ์๋ค.
2.prototype Pattern
MyClass.prototype.foo = function (arg1, arg2) {
...
};
Object.assign(MyClass.prototype, {
foo(arg1, arg2) {
...
}
});
- copy obj
Object.assign({ __proto__: obj.__proto__ }, obj);
Object.assign({}, obj) only ownProperty copy