# traceur-annotations

> A shim for Traceur's experimental annotations

Latest version **1.0.0** (published 2014-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install traceur-annotations
pnpm add traceur-annotations
yarn add traceur-annotations
bun add traceur-annotations
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-11-02 |
| First published | 2014-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matt Brennan |
| Maintainers | quarterto |
| Keywords | annotations, es6, traceur |

## Links

- npm: https://www.npmjs.com/package/traceur-annotations
- Repository: https://github.com/quarterto/traceur-annotations
- Issues: https://github.com/quarterto/traceur-annotations/issues
- npm.io page: https://npm.io/package/traceur-annotations

## Dependencies (1)

- [traceur](https://npm.io/package/traceur.md) 0.0.72

## Recent versions

- 1.0.0 (latest) — 2014-11-02

## README

```js
/* jshint esnext: true */
```

`traceur-annotations`
---

A shim for Traceur's annotations. Can be used 
directly as an annotation in Traceur:
```javascript
var Foo = Annotation.extend();
@Foo function bar() {}
```
or as a regular function in ES5/CoffeeScript/etc.:
```coffeescript
Foo = Annotation.extend()
Foo bar = ->
```
Traceur instantiates the class and adds it to the
annotatee's `annotations` array, so we simulate
that in other environments.

```js
class Annotation { init() {} }
```

#### `has :: Object → Maybe Annotation`
If the object is annotated with this annotation,
return the instance. Otherwise, return undefined.

```js
Annotation.has = function (obj) {
	return (obj.annotations || []).find((a) => a instanceof this);
};
```

#### `extend :: Object → typeof Annotation`
Create a new annotation based on this one. Can't do
this with regular subclassing, as we wouldn't be
able to dynamically delegate to the original class
if we need to instantiate it ourselves without
resorting to `arguments.callee`.

```js
Annotation.extend = function (proto = {}) {
	var sub = class extends this {
		constructor(...args) {
			if(this instanceof Annotation) {
				this.init(...args);
			} else {
				var obj = args.pop() || this;
				obj.annotations = obj.annotations || [];
				obj.annotations.push(new sub(...args));
				return obj; // for chaining
			}
		}
	};
	Object.assign(sub.prototype, proto);
	return sub;
};
 
module.exports = Annotation;
```

---
_Source: https://npm.io/package/traceur-annotations · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
