Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
fishbone
Advanced tools
Readme
c-{{{-<
A super lightweight (½kb) JavaScript library with automatic method chaining, automatic context binding, event support and simple inheritance.
Version: 1.0.1
this
is the context in all methodson
, off
event observer patternKlass = Model({ init: function(options){} })
- create a modelKlass2 = Klass.extend({ … })
- inherit from other classinstance = new Klass(options)
- create an instanceinstance.on(event, listener)
- observe a given eventinstance.off(event, [listener])
- remove listenerinstance.trigger(event, data)
- triggers an eventvar Model = require("./fishbone"); // require module (Node only)
var Pirate = Model({ // simple class creator
likes: "GROG", // instance properties
init: function(name){ // init is the main entrance
this.name = name; // options can be passed
this.grogs = 0;
},
drink: function(){ // instance method
if (++this.grogs >= 100){
this.trigger("drunk"); // trigger an event
}
},
yell: function(){
console.log("WANT MORE: " + this.likes); // this is always in context
}
});
var Captain = Pirate.extend({ // simple inheritance
likes: "STRONG GROG"
});
var captain = new Captain("Jack"), // create an instance
rounds = 20;
captain.on("drunk", captain.yell); // add event listener
function neverbeingcalled(){ // pseudo listener
console.error("AAR!");
}
captain.on("drunk", neverbeingcalled); // add event listener
captain.off("drunk", neverbeingcalled); // remove event listener
while (rounds--){
captain
.drink() // chaining FTW!
.drink() // chaining FTW!
.drink() // chaining FTW!
.drink() // chaining FTW!
.drink(); // chaining FTW!
}
Include fishbone.js
or copy and paste this:
Model=function a(b,c,d,e){function f(){var a=this,f={};a.on=function(a,b){(f[a]||
(f[a]=[])).push(b)},a.trigger=function(a,b){for(var c=f[a],d=0;c&&d<c.length;)c
[d++](b)},a.off=function(a,b){for(d=f[a]||[];b&&(c=d.indexOf(b))>-1;)d.splice(c
,1);f[a]=b?d:[]};for(c in b)d=b[c],a[c]=typeof d=="function"?function(){return(
d=this.apply(a,arguments))===e?a:d}.bind(d):d;a.init&&a.init.apply(a,arguments)
}return f.extend=function(f){d={};for(c in b)d[c]=b[c];for(c in f)d[c]=f[c],b[c
]!==e&&(d["__"+c]=b[c]);return a(d)},f},typeof module=="object"&&(module.exports
=Model); // c-{{{-<
Install via npm:
npm install fishbone
Fishbone runs in all modern browsers and Node.js.
If you want support for Internet Explorer 8 and below, you have to include the
.bind
and .indexOf
polyfills: https://github.com/aemkei/fishbone.js/blob/master/polyfills.js
Developed by Martin Kleppe at Ubilabs.
Released under the WTFPL license.
FAQs
A super lightweight (½kb) JavaScript library with automatic method chaining, automatic context binding, event support and simple inheritance.
The npm package fishbone receives a total of 36 weekly downloads. As such, fishbone popularity was classified as not popular.
We found that fishbone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.