4 ms·
I may have overlooked it, but I want actual proper integers. Not doubles, just integers. I also missed the awesome bind-operator. EG: const getFoo = () =>
by tobyhinloopen 8y ago
I may have overlooked it, but I want actual proper integers. Not doubles, just integers.
I also missed the awesome bind-operator. EG:
const getFoo = () => this.foo;
const bar = { foo: 1 };
console.log(bar::getFoo()); // 1
https://github.com/tc39/proposal-bind-operator https://github.com/tc39/proposal-bind-operator
- snek 8y agohttps://github.com/tc39/proposal-bigint https://github.com/tc39/proposal-bigint is shipping in v8 (chrome and node) and firefox is about to ship
- laacz 8y agoJust hung Chrome tab by running "2122n 12122n" in console. Had to use task manager to kill it.
- TheAceOfHearts 8y agoYou could use the same technique as asm.js for acquiring and handling integers. Unary `+` always produces a Number or an exception. Bitwise operators treat their operands as a sequence of 32 bits, so a bitwise OR with 0 will cast the value to a 32-bit integer: +value|0 There's also TypedArray [0]. I think you'll be interested in the BigInt proposal [1] [2], which is stage 3. It's already available in Chrome, and behind a flag in Firefox. Now that it's possible to accurately represent 64-bit values, we're getting BigInt64Array and BigUint64Array. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [1] https://github.com/tc39/proposal-bigint https://github.com/tc39/proposal-bigint [2] http://2ality.com/2017/03/es-integer.html http://2ality.com/2017/03/es-integer.html
- chrisseaton 8y ago> I want actual proper integers. Not doubles, just integers. Why exactly do you want that? Is it arbitrary precision you want? Is the 56 bits or whatever not enough for your use-case? Or do you find the range checks are too expensive in practice?
- karmakaze 8y agoYes 56 bits is not enough. I want compatibility with database types and any other protocols I choose to use rather than having a js-crippled subset.
- Dylan16807 8y ago53
- danielovichdk 8y agoBeing able to have a constant that is not constant makes me feel like i am being played for a fool somehow.
- Technetium_Hat 8y agoConstants are not deeply immutable in other languages either.
- existencebox 8y agoI have a feeling I'm walking into a very dumb question/obvious answer, but here goes. If you're putting getFoo at whatever level of scope that you'd run it over multiple bar objects that don't have it bound, why is it conceptually different than writing it as getFooOfBar(this_bar:hasfoo) => this_bar.foo (If you get my drift from the terrible notation; and you could drop the type-safety and just take an any obj if we're being more literal to your pseudocode) I had honestly not seen the bind operator used in at least the last decade, so perhaps the dissonance is just whatever corner of tech I work in having a distinct style/idioms.
- tbranyen 8y agoKeep in mind `this` is not scoped to arrow functions. So even if the syntax was added the way you proposed, this code wouldn't work or make sense.
- cribbles 8y agoThis code wouldn't execute properly, since arrow functions are scoped to the surrounding code block and cannot be rebound. You would need to use `function` for this: function getFoo() { return this.foo; }
- tobyhinloopen 8y agoYou're right! I forgot about that