npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone-class

v0.0.2

Published

Backbone Class is the missing 'Backbone.Class' in Backbone.js which provides clean JavaScript class inheritence via the Backbone.extend pattern

Downloads

488

Readme

Backbone Class

Class is the missing "Backbone.Class" in Backbone.js. It provides clean JavaScript inheritance via the Backbone.extend pattern and modified via Backbone-Super for simple this._super() calls. On instantiation, an initialize method is called and if a parameters object is passed, unless overridden, it will be pushed on to an options hash. Additionally, because backbone-class extends Backbone.Events, event dispatch can be achieved by adding listeners, triggering events, and removing listeners per the Backbone.js spec.

Best used with Browserify!

Installation

  • npm install backbone-class

Tests

  • npm install -g grunt-cli
  • npm install --dev
  • npm test

Example

Inheritance

var Klass = require('backbone-class');

var Person = Klass.extend({
  language: function() {
    return 'The method of human communication, either spoken or written, consisting of the use of words in a structured and conventional way.';
  }
});

var Animal = Person.extend({
  meaning: function() {
    return 'Intended to communicate something that is not directly expressed.';
  }
});

var animal = new Animal({
  defaultLanguage: 'Bark'
});

console.log( animal.options.defaultLanguage );
console.log( animal.language() );
console.log( animal.meaning() );

Supers

var Person = Klass.extend({
  language: function (lang) {
    return 'Speaking ' + (lang || 'English');
  }
});

var person = new Person();
console.log( person.language() ); // 'Speaking English'

var Animal = Person.extend({
  language: function(lang) {
    this._super(lang);
  }
});

var animal = new Animal();

console.log( animal.language('Bark') ); // 'Speaking Bark'

Eventing

var Person = Klass.extend({
  initialize: function() {
    this.on('speak', this.onSpeak.bind(this));
  },

  onSpeak: function() {
    return 'Hello Human :)';
  }
});

var person = new Person();
person.trigger('speak');

Changes

  • Bumped version to v0.0.2
  • Removed direct dependency on underscore & grunt
  • New owner and maintainer

More Info

Class inheritance mirrors Backbone.js precisely, but without the additional method baggage that is normally associated with Models, Views and Collections; feel free to check out Backbone.js for more info. Also, see Backbone-Super for more info on the _super() method.

Thanks