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

prototypal

v0.3.2

Published

prototypal inheritance done right

Downloads

20

Readme

prototypal

build status

Mit Style License

Where is Class ?

The initial Class module has been actually merged in this namespace where available.

Right now you can find more info about Class on this page

prototypal

All utilities in this namespace should work with every JavaScript engine, down to IE6, Opera Mini, duktape, nodejs, and all others.

How / Which File

npm install prototypal then var create = require('prototypal').create

Same is for bower install prototypal AMD module, however needed files are:

This package is registered in bower too.

prototypal.create(extend[, properties])

The API is very similar to the one proposed in lo-dash except it promotes instead of copying over the properties object whenever is possible (for better performance)

// a null object example
var n = prototypal.create(null);

// a generic inherited example
var a = {
      testa: 123
    },
    b = create(a, {
      testb: 456
    });

a.hasOwnProperty('testa'); // true
b.hasOwnProperty('testa'); // false
b.hasOwnProperty('testb'); // true
b.testa; // 123
b.testb; // 456

prototypal.Class(extend[, prototype])

Similar to prototypal.create, Class aim is to define reusable prototypes.

var Class = prototypal.Class;

var Null = Class(null, {
  // some optional method
  // that we might want to inherit
});

var n = new Null;
n instanceof Object; // false

The signature accepts a single argument as function, where its prototype will be used as inheritance chain, or an object to extend or a prototype.

var Rectangle = Class({
  constructor: function (width, height) {
    this.width = width;
    this.height = height;
  },
  toString: function () {
    return '[object Rectangle]';
  },
  area: function () {
    return this.width * this.height;
  }
});

var Square = Class(Rectangle, {
  constructor: function (size) {
    Rectangle.call(this, size, size);
  },
  toString: function () {
    return '[object Square]';
  }
});

var s = new Square(3);
s.area(); // 9
'' + s;   // [object Square]

prototypal.Class(extend[, function])

If the second argument is a function, it will be invoked with the extended parent/super passed as argument. In such case, the function needs to return descriptors.

var Rectangle = Class({
  constructor: function (width, height) {
    this.width = width;
    this.height = height;
  }
});

var Square = Class(Rectangle, function (parent) {
  // a closure with fast and private parent/super access
  // *must* return the descriptors object
  return {
    constructor: function (size) {
      parent.constructor.call(
        this, size, size
      );
    }
  };
});

ES5 prototypal.Class(extend[, prototype])

For JavaScript engines already compatible with ES5, the Class is the one proposed initially with Class.lazy, Class.descriptor, and Class.bound.

General Compatibility

Methods such prototypal.copy(), prototypal.create(), and prototypal.keys() are compatible with all JavaScript and JScript engines, down to Internet Explorer version 6, including Opera Mini and other server side based browsers.

You can test directly online if your browser is supported, including IE6.

However, while prototypal.Class is tested everywhere too, in those browsers where ES5 is available it behaves in a more powerful way (so if these are your browsers targets, just use all extra features such Class.lazy, Class.descriptor, or Class.bound).

All these platforms have been tested against the more powerful ES5 Class and its extra features:

  • iOS 5.1 or greater
  • Android 2.2 or greater
  • webOS 2.2 or greater
  • Kindle Fire Silk 3 or greater
  • Windows Phone 7 (IE9 Mobile) or greater
  • BlackBerry 10 or greater
  • Nokia Xpress on WP and Asha 11 or greater
  • Samsung Bada
  • Opera Mini and Opera Mini J2ME
  • FirefoxOS 1.0 or greater
  • Desktop IE9, Chrome, Opera, Safari, Midori, others
  • UC Browser and UC Browser Mini

On the server side, nashorn, duktape, nodejs, and Rhino work as expected too, as well as any other JavaScript server side engine probably should.

If you find any platform that is not green please file a bug and/or let me know, thank you.