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

kayclass

v2.1.2

Published

A Class implementation for JavaScript

Downloads

4

Readme

kay-framework:core license:mit tag:? build:? coverage:? npm: dependencies:? devDependencies:?

KayClass

Copyright © Kay Framework Team KayClass may be freely distributed under the MIT license. For all details and documentation: http://github.com/kay-framework/kayclass

KayClass is a simple Class implementation inspired by and built to mimic the ES6 class definition. It supports getter/setter prototype properties and static properties are included in much the same way as with a Backbone.JS class.

Prototype and static properties are inherited from the parent class, as well as property values such as enumerability and writability.

Named classes can be extended, and named classes with a prototype argument return the default constructor or the custom constructor - if provided - which references the parent via Class.super.

Usage

Class

Public: When a Class constructor is invoked with a name, proptotype and optional static properties, it returns a Constructor with the static properties, whose prototype is a composite of the prototype properties argument and any prototype properties of the parent.

Examples

var Class = require('kayclass');

var MyClass = Class('MyClass', {
        protoFn: function () {},
        get thing() {},
        set thing(athing) {
            this.athing = thing;
        }
    }, {
        staticFn: function () {}
    });

var myClassInstance = new MyClass();

// inheritance
assert(myClassInstance instanceof MyClass); // true
assert(myClassInstance instanceof Class); // false
assert(MyClass.prototype.protoFn === myClassInstance.protoFn); // true

Class.extends

Public: When given only a name argument, Class returns an object with an extends function. The extends function takes another class, a prototype properties object, and an optional static properties object.

Examples

var AnotherClass = Class('AnotherClass', {
        protoFn: function fn1() {},
        anotherProtoFn: function () {}
        get thing() {},
        set thing(athing) {
            this.athing = thing;
        }
    }, {
        staticFn: function () {}
    });

var MyClass = Class('MyClass').extends(AnotherClass, {
    protoFn: fn2() {},
    myProtoFn: function () {}
});

var myClassInstance = new MyClass();

// inheritance
assert(myClassInstance instanceof MyClass); // true
assert(myClassInstance instanceof AnotherClass); // true
assert(myClassInstance instanceof Class); // false

// child properties override parent properties of the same name
assert(myClassInstance.protoFn === '[Function: fn2]'); // true
// parent prototype properties are copied to the child prototype
assert(myClassInstance.anotherProtoFn === AnotherClass.prototype.anotherProtoFn); // true
// parent static properties are copied to the child
assert(MyClass.staticFn === AnotherClass.staticFn); // true


// Constructor/instance has a reference to its immediate parent via Class.super()
assert(Class.super(myClassInstance) === AnotherClass.prototype); // true