over the last couple days I have been studying some array methods and have seen stuff like [].splice.apply
and [].push.apply
with some parameters.
Now I think i understand splice for example
var tuna = ['bob', 'john' , 'papa' , 'greg'];
var newArr = []
tuna.splice(0,2,"hello");
console.log(tuna);
will output hello,papa,greg
, since it deletes 2 terms in the 0th indice.
I also know how apply works in the following context
var person = {
firstname: 'John',
lastname: 'Doe',
getFullName: function() {
var fullname = this.firstname + ' ' + this.lastname;
return fullname;
}
}
var logName = function(lang1, lang2) {
console.log('Logged: ' + this.getFullName());
console.log('Arguments: ' + lang1 + ' ' + lang2);
console.log('-----------');
}
var logPersonName = logName.bind(person);
logPersonName('en');
logName.call(person, 'en', 'es');
logName.apply(person, ['en', 'es']);
So what happens when we combine these two methods, or push with apply ? A simple example would really help.