View js-create-object.js
var a = Object.create(Object.constructor, {
aaa : {
value : 'vvv',
writable: true,
enumerable: true,
configurable: true
}
});
a.prototype.bbb = 'bbb';
View js-create-object.js
var a = Object.create(Object.prototype, {
aaa : {
value : 'vvv',
writable: true,
enumerable: true,
configurable: true
}
});
Object.getPrototypeOf(a); // Object { __definGetter__: function, __definSetter__: function, ... }
View js-craete-object.js
function TestObject () {
this.aaa = 'vvv'
};
var a = new TestObject();
var b = {
aaa : 'vvv'
};
View js-create-object.js
var a = Object.create(null, {
aaa : {
value : 'vvv',
writable: true,
enumerable: true,
configurable: true
}
});
console.log(a); // Object {aaa : 'vvv'}
View js-create-object.js
function FncObject() {
this.aaa = 'vvv';
}
var a = new FncObject();
// 생성자 함수로 객체 생성
var b = { aaa : 'vvv' };
// 리터널 객체 생성
View js-create-object.js
var Test = function() {
this.key1 = 'function value';
};
Test.prototype.key1 = 'prototype value';
var testIns = new Test();
console.log(testIns.key1); // 'function value'
console.log(testIns.__proto__.key1); // 'prototype value'
View js-create-object.js
var Test = function() {
this.key1 = 'value1';
};
var testIns = new Test();
Test.prototype.key2 = 'value2';
console.log(testIns.key2); // 'value2'
View js-create-object.js
var Test = function() {
this.key1 = 'value1';
};
var testIns = new Test();
Test.key2 = 'value2';
Test = function() {
this.key3 = 'value3';
View js-create-object.js
Me.prototype.phone = 'blackberry';
console.log(itsMe.phone); // 'blackberry'
View js-create-object.js
function Me(nickname, job) {
this.nickname = nickname;
this.jop = job;
}
var itsMe = new Me('falsy', 'developer');
console.log(itsMe.nickname); // 'falsy'