AsEvented
Micro event emitter which provides the observer pattern to JavaScript object.
Install / Use
/learn @mkuklis/AsEventedREADME
asEvented
Description
asEvented is a micro event emitter which provides the observer pattern to JavaScript object. It works in the browser and server (node.js). The code follows a functional mixins pattern described by Angus Croll a-fresh-look-at-javascript-mixins.
Usage
In browser include single JavaScript file:
<script src="asevented.js"></script>
On server install asEvented via npm first:
npm install asEvented
and then include it in your project with:
var asEvented = require('asEvented');
##Example Usage Define the constructor which will make use of asEvented:
function Model() {
this.id = 0;
}
Add (mixin) asEvented functionality to Model with:
asEvented.call(Model.prototype);
model has now access to trigger, bind/on, one and unbind/off functions
Add some functions to Model:
Model.prototype.setId = function (id) {
this.id = id;
this.trigger('change:id', id); // Model has now access to trigger
}
Create a new object and bind to change:id event:
var model = new Model();
model.bind('change:id', function (id) {
console.log('id changed to: ' + id);
});
Set a few model ids in order to trigger change:id event:
model.setId(1);
model.setId(2);
model.setId(3);
A single handler can be bound to multiple events by separating the events by spaces, though it will be ignorant of the triggering event:
model.bind('change:id change:pass', function() {
console.log('Event called.');
});
And multiple events can be unbound in one call:
model.unbind('onload onready');
##Contributors
- @mkuklis
- @rk
- @plalx
- @mpdaugherty
- @zspencer
- @travishorn
- @KenPowers
- @nazomikan
- @whiteinge
- @michaelrhodes
- @sirflo
- @vojtechkral
- @garex
##License:
<pre> (The MIT License) Copyright (c) 2015 Michal Kuklis </pre>Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。

