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

extend-light

v0.0.1

Published

extend light

Downloads

3

Readme

extend-light - npm

extend-light defines class in JavaScript. This is simple module providing a simple Class function to simplify class definition in JavaScript.

Easy to use, easy to inherit/extend.

no difficult keywords, no prototype, no __proto__, no Object.defineProperty, no Object.setPrototypeOf, etc ... needs constructor only.

Supports Google Chrome, Mozilla Firefox, Microsoft ie11/10/9/8/7/6 and Node.js/io.js.

Japanese version/■日本語版はこちら■

INSTALL:

NPM NPM

$ npm install extend-light

or

http://lightspeedworks.github.io/extend-light/extend-light.js

<script src="http://lightspeedworks.github.io/extend-light/extend-light.js"></script>

USAGE:

var extend = require('extend-light');

method: [BaseClass].extend([proto], [staticProps])

Define new class (constructor function) that inherited from Base Class.

Format

var YourClass = extend([proto], [staticProps]);
var YourSubClass = YourClass.extend([proto], [staticProps]);

Parameters

  • BaseClass: Base class or Super class for inherits
  • proto: the prototype object for your class, optional
    • constructor or new: constructor function, optional
    • any methods: any method or member function, optional
    • statics: the object for class or static properties, optional
      • any methods: any method or member function, optional
  • staticProps: the object for class or static properties, optional
    • any methods: any static method or class function, optional

You have to omit staticProps also, if you omit proto. You have to specify proto or {}, if you want to specify staticProps.

Returns

The newly defined class (constructor function). (Your class is subclass of BaseClass)

Details

A simple and quick sample:

var extend = require('extend-light');

var MyClass = extend({
  constructor: function MyClass(value) {
    this.value = value;
  },
  show: function show() {
    console.log(this.value);
  }
});

var myObj = new MyClass(5);
myObj.value++; // 5 -> 6
myObj.show();
myObj.value++; // 6 -> 7

EXAMPLES:

// Animal

// extend
var extend = require('extend-light');

// SimpleClass
var SimpleClass = extend('SimpleClass');
var s1 = new SimpleClass();

// Animal
var Animal = extend({
  constructor: function Animal(name) {
    if (!(this instanceof Animal))
      return new Animal(name);
    this.name = name;
  },
  introduce: function () {
    console.log('My name is ' + this.name);
  }
}, {
  animalClassMethod: function () {
    console.log('Animal class method');
  }
});
var a1 = new Animal('Annie');
a1.introduce(); // -> My name is Annie
Animal.animalClassMethod(); // -> Animal class method

// Bear
var Bear = Animal.extend('Bear');
var b1 = Bear('Pooh'); // new less
b1.introduce(); // -> My name is Pooh

var Cat = Animal.extend({
  constructor: function Cat(name) {
    if (!(this instanceof Cat))
      return new Cat(name);
    Cat.super_.apply(this, arguments);
  }
});
var c1 = new Cat('Kitty');
c1.introduce(); // -> My name is Kitty

var Dog = Animal.extend({
  constructor: function Dog(name) {
    if (!(this instanceof Dog))
      return new Dog(name);
    Dog.super_.apply(this, arguments);
  },
}, {
  init: function () {
    console.log('Dog class init');
  },
  dogClassMethod: function () {
    this.animalClassMethod();
    console.log('Dog class method');
  }
}); // -> Dog init
var d1 = new Dog('Hachi');
d1.introduce(); // -> My name is Hachi
Dog.dogClassMethod(); // -> Animal class method, Dog class method
Dog.animalClassMethod(); // -> Animal class method

SEE ALSO:

base-class-extend - npm

get-constructors - npm

LICENSE:

MIT