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 🙏

© 2026 – Pkg Stats / Ryan Hefner

parent.js

v0.0.4

Published

Javascript inheritance for a 5 years old

Readme

parent.js

Build Status

Javascript inheritance for a 5 years old

Javascript is great, we all know that. Prototypal inheritance is really powerful and some people can do awesome things with that, but let's face it, it has its quirks. Also 99% of the time we only want to create Classes and do simple inheritance. It shouldn't be complicated or prone to errors.

Parent.js is a micro library (less than 30 lines of code), that allows you to create javascript Classes (or in js terminology function constructors) and, at the same time, inherit easily from other Classes.

Use

For using this library, you just need to create your Classes with the following syntax:

var Person = Class({
  // Methods go here...
  ...
}, <BaseClass>)

And this is it! Please keep in mind that <BaseClass> is optional. Not every class needs to inherit! :smirk:. Let's see more examples:

var Person = Class({
  initialize: function (name, surname) {
    this.name = name;
    this.surname = surname;
  },
  sayHi: function () {
    return 'Hi I\'m a Person!!';
  }
});

var Student = Class({
  initialize: function (name, surname, bachelor) {
    this.super.initialize(name, surname);
    this.bachelor = bachelor;
  },
  study: function () {
    return 'I\'m Studying!'
    
  },
  sayHi: function () {
    return 'Hi I\'m a Student!!';
  }
}, Person);

var student = new Student('Jose', 'Vidal', 'Computer Science');

console.dir(student.name, student.bachelor);
// Output: "Jose, Computer Science" 

console.dir(student.sayHi());
// Output: "Hi I'm a Student!" 

console.dir(student.super.sayHi());
// Output: "Hi I'm a Person!" 

console.log(s1 instanceof Student);
// Output: true 
console.log(s1 instanceof Person);
// Output: true 

You can see how the use of parent's methods is trivial with the attribute super from the instances.

Advanced Use

A nice feature is the possibility of creating class methods by prepending __ (two underscores) to the name of the method.

var Person = Class({
  initialize: function (name, surname) {
    this.name = name;
    this.surname = surname;
  },
  __thisIsAClassMethod: function () {
    return 'Hi I\'m a classmethod!';
  },
  thisIsAnInstanceMethod: function () {
    return 'Hi I\'m an instancemethod!';
  }
});

var person = new Person('Jose', 'Vidal');

// Class:
console.log(Person.thisIsAClassMethod());
// Output: 'Hi I\'m a classmethod!'

console.log(Person.thisIsAnInstanceMethod());
// Output: TypeError: undefined is not a function

// Instance:
console.log(person.thisIsAClassMethod());
// Output: TypeError: undefined is not a function

console.log(person.thisIsAnInstanceMethod());
// Output: 'Hi I\'m an instancemethod!'

Installation

bower install parent.js

or

npm install parent.js

Enjoy!

Contribute

Simply make a PR.

Licente

MIT