0
不幸的是,下面的代碼不會在螢火蟲控制檯上打印任何內容,它也不會拋出錯誤,不知道這段代碼有什麼問題。試圖讓代碼使用javascript調用工作
$(document).ready(function(){
var animals = [
{species: 'Lion', name: 'King'},
{species: 'Whale', name: 'Fail'}
];
for (var i = 0; i < animals.length; i++) {
(function (i) {
this.print = function() {
console.log('#' + i + ' ' + this.species + ': ' + this.name);
}
}).call(animals[i], i);
}
});
你在任何時候都不會調用'this.print()'。 – JJJ 2012-07-28 06:15:36