Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
You can take the fake array even further by forcing Array's prototype onto it:
consta={'0':'first','1':'second','2':'third',length:3};a.__proto__=Object.create(Array.prototype)a.push('fourth')// \// Now we can use push!//// We can also use map!// /a.map(x=>x.toUpperCase())// [ 'FIRST', 'SECOND', 'THIRD', 'FOURTH' ]
Correct, the power of prototypal inheritance allows you to quickly compose objects like that. 👌
The point of the exercise was to implement the methods directly, rather than just piggybacking off of the existing ones, though. It could have easily been an article about how to use prototypes to build your custom arrays, something that I might pick up a later date.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can take the fake array even further by forcing Array's prototype onto it:
btw... never write code like this ^
Cheers!
Correct, the power of prototypal inheritance allows you to quickly compose objects like that. 👌
The point of the exercise was to implement the methods directly, rather than just piggybacking off of the existing ones, though. It could have easily been an article about how to use prototypes to build your custom arrays, something that I might pick up a later date.