如果我有一個String實例,並修改其構造函數的原型,那麼每個String實例的原型都具有該屬性(如預期的那樣)。瞭解Javascript原型鏈
"test string".constructor.prototype.thing = function() {return this;}
console.log("new string".thing());//prints "new string"
但是,如果我修改字符串構造函數的構造函數的原型,那麼這將不再有效:如果
String.constructor.prototype.thing = function() {return this;}
console.log("new string".thing());//returns "new string".thing() is not a function
同樣的事情,我使用的字符串。 proto語法。爲什麼是這樣?當我在尋找一個屬性時,我的印象是,JavaScript將一直沿着原型鏈向上。如果我將屬性添加到String.constructor.prototype,那麼String將不具有該屬性,但其父對象將更正?因此,String的所有實例都應該有權訪問該屬性。我的思想在哪裏錯了?
可能有[\ _ \ _ proto \ _ \ _ VS的重複。原型在JavaScript](http://stackoverflow.com/questions/9959727/proto-vs-prototype-in-javascript) – rockerest