有沒有這樣一種情況,constructor屬性會在物件/函式/類本身上定義,或者它是否只出現在prototype?例如:
let a = new Array();
console.log(a.hasOwnProperty('constructor'), a.constructor);
// false -- constructor not defined on Array, but Array.prototype
let f = function(){};
console.log(f.hasOwnProperty('constructor'), f.constructor);
// false -- constructor not defined on function, but function.prototype
uj5u.com熱心網友回復:
這種事情在技術上是可能發生的,但這是一種代碼味道。
function Klass(){
this.constructor = Klass;
}
const k = new Klass();
console.log(k.hasOwnProperty('constructor'), k);
(當有人不正確地
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/459675.html
標籤:javascript
