function xyz() {}
function abc() {}
var p = new xyz();
abc.prototype = p;
var o = new abc();
o.__proto__ === p // true
o.__proto__.__proto__ === xyz.prototype // true
o.__proto__.__proto__.__proto__ === Object.prototype // true
o.__proto__.__proto__.__proto__.__proto__ === null // true
または:
function xyz() {}
function abc() {}
var p = Object.create(xyz.prototype);
abc.prototype = p;
var o = new abc();
o.__proto__ === p // true
o.__proto__.__proto__ === xyz.prototype // true
o.__proto__.__proto__.__proto__ === Object.prototype // true
o.__proto__.__proto__.__proto__.__proto__ === null // true
または:
class xyz {}
class abc extends xyz {}
var o = new abc();
o.__proto__.__proto__ === xyz.prototype // true
o.__proto__.__proto__.__proto__ === Object.prototype // true
o.__proto__.__proto__.__proto__.__proto__ === null // true
または:
function xyz() {}
const abc = {
__proto__: Object.create(xyz.prototype)
}
abc.__proto__.__proto__ === xyz.prototype // true
abc.__proto__.__proto__.__proto__ === Object.prototype // true
abc.__proto__.__proto__.__proto__.__proto__ === null // true
または:
function xyz() {}
function abc() {}
Object.setPrototypeOf(abc.prototype, xyz.prototype);
var o = new abc();
o.__proto__.__proto__ === xyz.prototype // true
o.__proto__.__proto__.__proto__ === Object.prototype // true
o.__proto__.__proto__.__proto__.__proto__ === null // true
出典
2017-06-16 17:14:46
Ben
'Object.setPrototypeOf(abc.prototype、xyz.prototype); ' – 4castle
コードを正しくフォーマットするためにバッククォートを使用してください。 –
あなたは何を達成しようとしていますか?あるいは、これはある種の学問的学習の練習ですか? –