Socket
Socket
Sign inDemoInstall

fishbone

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fishbone

A super lightweight (½kb) JavaScript library - made for hungy pirates.


Version published
Weekly downloads
12
decreased by-40%
Maintainers
1
Install size
4.50 kB
Created
Weekly downloads
 

Readme

Source

Fishbone.js c-{{{-<

A super lightweight (½kb) JavaScript library – made for hungy pirates.

Features

  • clean and simple constructor
  • scoped instance methods
  • event observer pattern
  • automatic method chaining
  • no dependencies
  • cross browser & Node.js support
  • < 512 bytes minified (300 gzip)

Usage

  • Model({ init: function(options){} }) - create a model
  • new Model(options) - create an instance
  • #on(event, listener) - observe a given event
  • #off(event, [listener]) - remove listener
  • #trigger(event, data) - triggers an event

Example

var Model = require("./fishbone");

var Pirate = Model({
  init: function(name){
    this.name = name;
    this.grogs = 0;
  },
  drink: function(){
    if (++this.grogs >= 100){
      this.trigger("drunk");
    }
  },
  sing: function(){
    console.log("ARR: " + this.name + " WANT MORE!");
  }
});

var captain = new Pirate("Jack"),
  rounds = 20;

captain.on("drunk", captain.sing);

while (rounds--){ 
  captain.drink().drink().drink().drink().drink(); 
}

Install

Copy and paste this:

function Model(a){return function(b){var c=this,d={},e,f,g;c.on=function(a,b)
{var c=d[a]||(d[a]=[]);c.push(b)},c.trigger=function(a,b){for(var c=d[a],e=0;
c&&e<c.length;e++)c[e](b)},c.off=function(a,b){for(var c=d[a]||[],e;b&&(e=c.
indexOf(b))>-1;)c.splice(e,1);d[a]=c};for(f in a)e=a[f],a.hasOwnProperty(f)&&
typeof e=="function"&&(c[f]=function(){var a=this.apply(c,arguments);return a
===g?c:a}.bind(e));c.init(b)}}typeof module=="object"&&(module.exports=Model);

About

Developed by Martin Kleppe at Ubilabs.

Released under the WTFPL license.

FAQs

Last updated on 16 Nov 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc