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

class-256.js

v2.0.1

Published

Less than 256 byte JavaScript classical inheritance pattern library

Downloads

19

Readme

class-256.js

npm version Bower version devDependency Status Travis

class-256.js is a less than 256 byte JavaScript classical inheritance pattern library (221 bytes minified or 363 bytes minified with UMD pattern).
Originally based on augment and extend (repository no longer exists).

Features

  • OOP style declaration
  • Constructor methods (optional - if you don't provide one, the parent's constructor will be called upon instantiation)
  • Working instanceof
  • Supports public and private/privileged methods, public and private static properties
  • Non-overridden public properties/methods defined in parent naturally accessible
  • Overridden public methods defined in parent accessible through parent parameter

Basic usage

var HelloWorld = Class.extend(function() { // default name of .extend() can be changed via constant
	this.greeting = 'Hello '; // public property

	var world = 'World!'; // private static property

	this.constructor = function(greeting) { // default name of .constructor() can be changed via constant
		if (typeof greeting != 'undefined') {
			this.greeting = greeting;
		}
	};

	this.say = function() { // public method
		return privileged.call(this);
	};

	function privileged() { // private/privileged method
		return this.greeting + world;
	}

	this.setWorld = function(newWorld) {
		world = newWorld;
	};

	this.getWorld = function() {
		return world;
	};
});

var helloWorld = new HelloWorld();

assert.equal(helloWorld.say(), 'Hello World!');
assert.instanceOf(helloWorld, HelloWorld);

var hiWorld = new HelloWorld('Hi ');

assert.equal(hiWorld.say(), 'Hi World!');
assert.instanceOf(hiWorld, HelloWorld);

helloWorld.setWorld('Earth!');
assert.equal(helloWorld.say(), 'Hello Earth!');
assert.equal(hiWorld.say(), 'Hi Earth!'); // Because 'world' is a static property

Extending

function isNonEmptyString(value) {
	return typeof value == 'string' && value.length > 0;
}

var Base = Class.extend(function() {
	this.name = '';

	this.constructor = function(name) {
		this.name = name;
	};

	// check name
	this.isValid = function() {
		return isNonEmptyString(this.name);
	};
});


var Extended = Base.extend(function(parent) {
	this.address = '';

	this.constructor = function(name, address) {
		parent.constructor.call(this, name); // call parent constructor
		// could be also written as: this.name = name;

		this.address = address;
	};

	// check name and address
	this.isValid = function() {
		return parent.isValid.call(this) && isNonEmptyString(this.address);
		// could be also written as: return isNonEmptyString(this.name) && isNonEmptyString(this.address);
	};
});

var emptyExample = new Extended(null, null);

assert.isFalse(emptyExample.isValid());

var nameExample = new Extended('John', null);

assert.isFalse(nameExample.isValid());

var addressExample = new Extended(null, 'London');

assert.isFalse(addressExample.isValid());

var validExample = new Extended('John', 'London');

assert.isTrue(validExample.isValid());

For more examples see test/test.js.

Installation

NPM

npm install class-256.js

Bower

bower install class-256.js

Browser

<script src="https://github.com/koffeine/class-256.js/blob/master/dist/class.umd.min.js"></script>

Files

| UMD | Minified | File | |:----|:---------|:----------------------------------------------------------------------------------------------------| | ✓ | ✓ | dist/class.umd.min.js | | ✓ | | dist/class.umd.js |

Develop

Requirements

Building requires NodeJS version 6.0.0 or later.

Set up

npm install

Build

Running the following command will start Gulp, which will run ESLint, create the UMD version, run Mocha/Chai tests and run UglifyJS:

gulp

License

Copyright © 2015-2018 Kornél Horváth

Licensed under the MIT License.