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

dnaof

v0.0.7

Published

kindof(), .can., dnaof(), .create() - inheritance made easy

Downloads

20

Readme

dnaof

kindof(), .can., dnaof() - inheritance made easy

Ever struggled with prototype inheritance? Ever wandered why examples of inheritance do not show inheritance deeper than one level? Want it quick, easy and painless?

kindof() -- creates a new kind (you might want to call it a class or a type)

.can. -- assign a new ability to a kind (method, function)

dnaof() -- call the ancestor method (aka the inherited or super)

======

EXAMPLE

Demonstrate creation of kinds, creating and calling both overloaded and not overloaded methods.

OUTPUT

bob can chat
alice can chat, alice can talk
candy can chat, candy can talk, candy can discuss
bzzzz.z.z.z... (alice)
bzzzz.z.z.z... (bob)
bzzzz.z.z.z... (candy)

CODE

require('./dnaof')

// Create a kind of an idiot without an ancestor:

var idiot = kindof()

// Tell what it can do:

idiot.can.say = function() { return this.name + ' can chat' }
idiot.can.rest = function() { console.log('bzzzz.z.z.z... (' + this.name + ')') }

// New kind of smart inherits from a kind of idiot

var smart = kindof(idiot)

// He can also say something:

smart.can.say = function() {
	// He can say something new, and he can
	//    say the same thing that an idiot can:
	return dnaof(this, 'say') + ', ' + this.name + ' can talk'
}

// A kind of genious can do the same things as
//    an idiot and smart can, and even more:

var genious = kindof(smart)
genious.can.say = function() {
	return dnaof(this, 'say') + ', ' + this.name + ' can discuss'
}

// instantiate three persons:

var bob = new idiot
var alice = new smart
var candy = new genious

// Assign properties, because to make life simpler
//    we do not initialize anything during creation
//    yes, we separate creation from feeding and teaching:

bob.name = 'bob'
alice.name = 'alice'
candy.name = 'candy'

// Let them talk:

console.log(bob.say())
console.log(alice.say())
console.log(candy.say())

// Let them take some rest:

alice.rest(), bob.rest(), candy.rest()