var arr = [1,2,3,4,5,6];
var total = arr.reduce(function(j, i){
return j + i;
})
console.log(total);
var arr2 = [
{money: 10, num: 1},
{money: 16, num: 2},
{money: 4.5, num: 1},
{money: 0.12, num: 10}
]
var total2 = arr2.reduce(function(total, goods){
return total + goods.money * goods.num;
}, 0);
console.log(total2);
var obj = {
hi: 'hello',
name: '张三',
say: function(){
console.log(this.hi+' '+this.name);
},
console: function(text){
console.log(text);
}
}
var obj1 = {
hi: 'hi',
name: '李四'
}
obj.say();
obj.say.call(obj1);
obj.console.call(obj, '这是call函数');
var obj2 = {
hi: 'hello',
name: '张三',
say: function(){
console.log(this.hi+' '+this.name);
},
console: function(text){
console.log(text);
}
}
var obj3 = {
hi: 'hi',
name: '李四'
}
obj2.say();
obj2.say.apply(obj3);
obj2.console.apply(obj3, ['这是apply函数']);
var obj4 = {
hi: 'hello',
name: '张三',
say: function(){
console.log(this.hi+' '+this.name);
},
console: function(text){
console.log(text);
}
}
var obj5 = {
hi: 'hi',
name: '李四'
}
obj4.say();
obj4.say.bind(obj5)();
console