3 ms·
Technically, the special API is because arrays extend Array.prototype. You could create an object that does the same, and push(), pop(), etc would work.* Try g
by jdlshore 13y ago
Technically, the special API is because arrays extend Array.prototype. You could create an object that does the same, and push(), pop(), etc would work.*
Try going to http://www.objectplayground.com http://www.objectplayground.com and putting in the following code, selecting the "Show built-in objects" option, and evaluating:
this.array = [];
this.object = Object.create(Array.prototype);
this.object.push("foo");
this.object.push("bar");
*Well, they sort of work. They use and modify the "length" property, so you could see some weird behavior under some circumstances. Not recommended for production use. :-)
- cema 13y agoYes, but a literal will still be either an array or an object, so that var arr = ['a','b'] will be different from var obj = {0:'a',1:'b'}