Unfortunately this code below does not print anything on the firebug console, neither does it throw an error, not sure what is wrong with this code.
$(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);
}
});
You are assigning a
.print()method to each object in theanimalsarray, but you are never calling that method so there is no expected output from this code.