# onlooker

> observer

Latest version **1.0.4** (published 2015-02-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install onlooker
pnpm add onlooker
yarn add onlooker
bun add onlooker
```

## 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.4 |
| Published | 2015-02-10 |
| First published | 2014-12-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Fergus Ruston |
| Maintainers | ergusto |

## Links

- npm: https://www.npmjs.com/package/onlooker
- Repository: https://github.com/ergusto/onlooker
- Issues: https://github.com/ergusto/onlooker/issues
- npm.io page: https://npm.io/package/onlooker

## Recent versions

- 1.0.4 (latest) — 2015-02-10
- 1.0.2 — 2014-12-28
- 1.0.1 — 2014-12-14
- 1.0.0 — 2014-12-10

## README

# onlooker

add observer functionality to any object
 
```javascript
var ObserverMixin = require('onlooker');

var Person = function(name) {
	this.name = name;
	this.on('nameChange', this.shoutName);
	return this;
}

ObserverMixin(Person.prototype);

Person.prototype.shoutName = function(newName, oldName) {
	console.log('MY NAME IS', newName.toUpperCase());
};

Person.prototype.changeName = function(name) {
	var oldName = this.name;
	this.name = name;
	this.trigger('nameChange', this.name, oldName);
};
```

```javascript
var tintin = new Person('Tintin');

tintin.changeName('Snowy');

// logs: MY NAME IS SNOWY
```

adds on, off, and trigger methods to the specified object. 

supports space delimited event names - e.g:

```javascript
obj.trigger('created updated', args);
```

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