Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECMAScript proposal: Vampire operator #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions proposal-vampire-operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ECMAScript proposal: Vampire operator
- [Motivation](#motivation)
- [High-level API](#high-level-api)
- [FAQ](#faq)

## Motivation

The vampire operator (',..,') is extremely useful in imperative programming, as it allows to transfer properties from one object to another with mutation as a side effect.

## High-level API
### Objects
```js
const vampire = {};
const prey = {
flag: true,
count: 42,
items: []
};

vampire ,.., prey;
console.log(vampire);
// {flag: true, count: 42, items: Array(0)}
console.log(prey);
// {}
```
### Arrays
```js
const vampire = [];
const prey = [42, 'x', NaN];

vampire ,.., prey;
console.log(vampire);
// (3) [42, "x", NaN]
console.log(prey);
// []
```
### FAQ
#### What are the restrictions on using the vampire operator?
Use with caution on HolyJs, especially near water.
#### Should I be wary of a silver bullet?
No Silver Bullet.
#### Is there a danger of using the vampire operator on the call stack?
No, but make sure it's a stack, not a stake.