In this activity, you will examine the works of. You will examine the. Augusto Martelli Casona Vianello Sigla TV Per Pianoforte PDF Больше задач.Q:
JavaScript and "as" keyword
I noticed the following from a JavaScript book I have on my bookshelf. I have highlighted the new line with the "as" keyword:
var people = [
{name: 'Bob', age: 20},
{name: 'Joe', age: 27},
{name: 'Ann', age: 25},
];
var newPeople = people.slice(0); //copy the first three
newPeople = [{name: 'Jack', age: 12},
{name: 'Bill', age: 18},
{name: 'Mary', age: 24}]; //copy the second three
newPeople.splice(0, 3, {name: 'Frank', age: 26});
If I have to re-write this code, what would it be?
var people = [
{name: 'Bob', age: 20},
{name: 'Joe', age: 27},
{name: 'Ann', age: 25},
];
var newPeople = people.slice(0); //copy the first three
newPeople = [{name: 'Jack', age: 12},
{name: 'Bill', age: 18},
{name: 'Mary', age: 24}]; //copy the second three
newPeople.splice(0, 3, {name: 'Frank', age: 26});
A:
This is just a simple assignment, and nothing particularly interesting
newPeople.splice(0, 3, {name: 'Frank', age: 26});
I would personally just write
newPeople = newPeople.slice(0);
newPeople.splice(0, 3, {name: 'Frank', age: 26});
As you have it written, you're using the result of the slice() operation which is an array, but you're using it as a key in the splice() method. Also, in splice(), you can use an array as a source. So what happens is you be359ba680
Related links:
Comentários