https://github.com/matrixai/js-reference-pointer
Wrap a primitive value in a reference pointer, and pass by reference!
https://github.com/matrixai/js-reference-pointer
javascript nodejs pointer reference
Last synced: 5 months ago
JSON representation
Wrap a primitive value in a reference pointer, and pass by reference!
- Host: GitHub
- URL: https://github.com/matrixai/js-reference-pointer
- Owner: MatrixAI
- License: apache-2.0
- Created: 2018-02-02T06:54:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-05T10:28:06.000Z (almost 8 years ago)
- Last Synced: 2024-10-14T01:08:43.113Z (about 1 year ago)
- Topics: javascript, nodejs, pointer, reference
- Language: JavaScript
- Homepage: https://matrix.ai
- Size: 1.19 MB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reference Pointer
This library simply wraps a primitive value (number, string) into an object, so instead of passing a value around, you pass the object around. This allows you do pass-by-reference. This is basically JavaScript's equivalent of a pointer.
Basic Usage
-------------
```sh
npm install --save 'reference-pointer';
```
```js
import Reference from 'reference-pointer';
const changed = new Reference(false);
function changeBool (changed) {
changed.set(true);
}
changeBool(changed);
console.log(changed.get()); // true
```
Development
------------
To build this package for release:
```
npm run build
```
It will run tests, generate documentation and output multiple targets. One for browsers and one for nodejs. See `rollup.config.js` to see the target specification.
If your bundler is aware of the module field in `package.json`, you'll get the ES6 module directly.
Once you've updated the package run this:
```
npm version
npm publish
```