function MyString(str) {
var newStr = [];
for(var count in str) {
newStr[count] = str[count];
count++;
};
this.length = count;
return newStr;
}
MyString.prototype.abc=function(){
console.log("123")
}
var s = new MyString("hello");
s.abc();
浏览器报错 :demo2.html:27 Uncaught TypeError: s.abc is not a function(…)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
建议复习一下构造函数
你最后
所以你s得到的不是构造函数MyString的实例对象,而是newStr这个数组