https://github.com/jwerle/secret-nan
NaN - the true singleton (and the hax that you can conceive)
https://github.com/jwerle/secret-nan
Last synced: 10 months ago
JSON representation
NaN - the true singleton (and the hax that you can conceive)
- Host: GitHub
- URL: https://github.com/jwerle/secret-nan
- Owner: jwerle
- License: mit
- Created: 2016-05-25T20:58:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-25T21:11:32.000Z (about 10 years ago)
- Last Synced: 2025-03-14T03:17:53.001Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
NaN secrets
===========
`NaN` is a special value in javascript. It is one of few built in values
that can represent a true invariant. `NaN` is a `number`, or a `Number`
instance. Every `prototype` property (scalar, method, object) on the
`Number` prototype is inherited by `NaN`. `NaN` with the help of a
`Symbol` can enclose values only accessible to occurences of `NaN`. We
can achieve this by adding a `.set(key, value);` method to the
`Number.prototype` object.
```js
NaN.set('kinkajou' 'bradley')
(4).set('monkey', 'brian')
0xff.set('cat', 'sienna')
0..set('dog', 'apollo')
console.log(NaN.kinkajou); // 'bradley'
console.log((4).monkey); // undefined
console.log(0xff.cat); // undefined
console.log(0..dog); // undefined
```
## or ...
... you could probably do this with any built-in scalar like
`{ -Infinity, ..., -1, 0, 1, ..., +Infinity }` or `true, false` with the
exception of `null` and `undefined`
## anyways ...
... yolo
## more ...
* https://www.smashingmagazine.com/2011/05/10-oddities-and-secrets-about-javascript/
* http://www.programering.com/a/MDNxcjNwATk.html
* http://ariya.ofilabs.com/2014/05/the-curious-case-of-javascript-nan.html
## license
do wtf ever... *MIT*