Michael Theriot (2016-04-18T19:31:55.000Z)
michael.lee.theriot at gmail.com (2016-04-19T05:14:38.621Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { apply: (target, thisArg, arguments) => Reflect.get(target, getProp(target, arguments[0])) }; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), handler) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ``` ... but you can't set anything with the `arr(-1)` syntax obviously.
michael.lee.theriot at gmail.com (2016-04-19T01:09:14.823Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => Reflect.get(target, getProp(target, arguments[0])) }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ``` ... but you can't set anything with the `arr(-1)` syntax obviously.
michael.lee.theriot at gmail.com (2016-04-19T01:07:41.084Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => Reflect.get(target, getProp(target, arguments[0])) }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ``` ... but you can't set anything with the `arr(-1)` syntax obviously.
michael.lee.theriot at gmail.com (2016-04-19T01:07:18.748Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => Reflect.get(target, getProp(target, arguments[0])) }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ``` ... but you can't set anything with the `arr(2)` syntax obviously.
michael.lee.theriot at gmail.com (2016-04-19T01:05:22.922Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ```js var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => Reflect.get(target, getProp(target, arguments[0])) }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ```
michael.lee.theriot at gmail.com (2016-04-19T01:04:23.086Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => Reflect.get(target, getProp(target, arguments[0])) }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ```
michael.lee.theriot at gmail.com (2016-04-19T00:59:06.221Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeof issue... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => target[getProp(target, arguments[0])] }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ```
michael.lee.theriot at gmail.com (2016-04-19T00:58:43.322Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap. You can also make a callable array without the typeoff issue... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var CallableArray = new Proxy(function CallableArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, CallableArray), { apply: (target, thisArg, arguments) => target[getProp(target, arguments[0])] }) }); Reflect.setPrototypeOf(CallableArray, Array); CallableArray.prototype = Object.create(Array.prototype); ```
michael.lee.theriot at gmail.com (2016-04-18T19:38:23.362Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap.
michael.lee.theriot at gmail.com (2016-04-18T19:37:06.654Z)
This can be trivially done with proxies. I don't think arrays should have a special trap dependent on whether or not a symbol is set. If I were to make a custom array with proxies I would then have to check if someone changed standard behavior by inserting a symbol, and pass the symbol to the target just to work properly. If the `var arr = [1,2,3];` syntax is the real reason to change default behavior then just use `Array.from` like such `var arr = InvertedArray.from([1,2,3]);`. See below... ``` var getProp = (target, property) => typeof property !== 'symbol' && target.length && property < 0 && property >= -target.length ? +property + target.length : property; var handler = { get: (target, property, receiver) => Reflect.get(target, getProp(target, property), receiver), set: (target, property, value, receiver) => Reflect.set(target, getProp(target, property), value, receiver) }; var InvertedArray = new Proxy(function InvertedArray(arg1) {}, { construct: (target, arguments, newTarget) => new Proxy(Reflect.construct(Array, arguments, InvertedArray), handler) }); Reflect.setPrototypeOf(InvertedArray, Array); InvertedArray.prototype = Object.create(Array.prototype); ``` Arrays are effectively regular objects with traps on get/set to update the length property. I don't think they should have a special new syntax to access negative indices like `arr[:-1]` since it would logically have to work on all objects and is dependent on a length property; it's just syntactic sugar for yet another trap.