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

pseudoclass

v1.0.3

Published

> An OOP framework for Node.js and the browser

Downloads

101

Readme

PseudoClass NPM version Build status Code coverage status

An OOP framework for Node.js and the browser

Sweet syntactic sugar for prototypal inheritance.

PseudoClass provides construct(), destruct(), _super(), and an init() method that runs after construction is complete.

All the same under the hood.

PseudoClass uses JavaScript constructors and prototypal inheritance under the hood. Monkey-patching, instanceof, and instance.constructor all work as expected.

Not afraid to mix it up.

Mixins can be added when a class is declared using the mixins option or after instantiation with the instance.mixin() method.

Crushes boilerplate with a classy touch.

Stay classy and boilerplate-free with string-based toString declarations and automatic chaining of construct() and destruct().

Define and override properties effortlessly.

Make instance properties non-writable, non-enumerable, or employ setters & getters with the properties option, then inherit and override individually.

Dependencies

PseudoClass is completely standalone. All you need to stay classy is Class.js.

Compatibility

As PseudoClass makes use of ECMAScript 5 features, it is only compatible with modern browsers.

  • IE 9+
  • Firefox 4+
  • Chrome 6+
  • Safari 5+
  • Opera 12+
  • Node 0.8+

PseudoClass can be used in a Node, AMD, or browser environment out of the box.

Usage

PseudoClass empowers you without getting in your way. See the examples below to see how PseudoClass makes prototypal inheritance painless.

Define a class

var Parent = Class({
  toString: 'Parent',
  properties: {
    visible: {
      value: true,
      enumerable: true
    }
  },
  construct: function() {
    console.log('Parent: Constructing');
  },
  destruct: function() {
    console.log('Parent: Destructing');
  },
  doStuff: function() {
    console.log('Parent: Doing stuff');
  }
});

Define a mixin

A mixin is a set methods you can plug into any class. Mixins can use _super, just like normal methods.

var stuffDoer = {
  doStuff: function() {
    this._super();
    console.log('Mixin: Doing stuff');
  }
};

Inherit from Parent and add a mixin to the class prototype

Mixins added at declaration time become part of the prototype.

var Child = Parent.extend({
  toString: 'Child',
  mixins: [stuffDoer],
  properties: {
    visible: {
      value: false // Only override the value
    }
  },
  construct: function() {
    console.log(this+': Constructing');
  },
  destruct: function() {
    console.log(this+': Destructing');
  },
  doStuff: function() {
    this._super();
    console.log(this+': Doing stuff');
  }
});

Create an instance

var child = new Child();
/* Output:
  Parent: Constructing
  Child: Constructing
*/

Call a method

child.doStuff();
/* Output:
  Parent: Doing stuff
  Child: Doing stuff
  Mixin: Doing stuff
*/

Add a mixin to the instance

Mixins added after instantiation become part of the instance.

child.mixin({
  doMoreStuff: function() {
    console.log(this+': Doing more stuff')
  }
});

child.doMoreStuff();
/* Output:
  Child: Doing more stuff
*/

Check yo' self

console.log(child.instanceOf(Child)); // true
console.log(child.instanceOf(Parent)); // true
console.log(child.constructor === Child) // true
console.log(child+''); // 'Child'

Wreck yo' self

child.destruct();
/* Output:
  Child: Destructing
  Parent: Destructing
*/

No-conflict by default

PseudoClass is always accessible as PseudoClass. If you're using another library that defines Class, you can still use PseudoClass by referencing PseudoClass instead.

License

PseudoClass is licensed under the permissive BSD license.