1
在此之後代碼第一:爲什麼Object.keys(Array.prototype)返回空數組?
function User(name, dept){
this.username = name;
this.dept = dept;
this.talk = function(){
return "Hi";
};
}
function Employee(){
User.apply(this, Array.prototype.slice.call(arguments));
}
Employee.prototype = new User();
for(var x in Employee.prototype)
console.log(x, ':', Employee.prototype[x]);
Object.keys(Employee.prototype);//prints array of keys...
它打印出精美...
Array.prototype; //[]
Array.prototype.slice; // Function
var o = Array.prototype;
for(var i in o) console.log(i, ':', o[i]); //it doesn't execute
Object.keys(Array.prototype); //[] - ???
如何解釋這種現象?
我們可以模仿我們嘗試創建的構造函數嗎?
因爲它們是不可枚舉的屬性。 – elclanrs 2014-12-03 09:24:21
Object.getOwnPropertyNames(Array.prototype) – havenchyk 2014-12-03 09:48:33
關於時間有人回答了這個...... :) – deostroll 2014-12-04 04:03:26