node package manager


create functions with prototypal inheritance


Create functions with prototypal inheritance

AKA, let's combine the Substack pattern with the Builder pattern.

usage example

var FunctionCreate = require('functioncreate')

var Greeter = FunctionCreate(function (name) { = name

  return function () {
    return 'hey ' +

now we can add functions to Greeter's prototype, like we would with an object:

Greeter.prototype.callMe = function (name) { = name

var greet = Greeter('Amy')

greet().should.equal('hey Amy')


greet().should.equal('hey Maybey')

Unlike true prototypal inheritance, properties and methods on the prototype are copied over to the new function at construction time and further runtime modifications will not be copied.

running the tests

From package root:

$ npm install
$ npm test

performance considerations

If you're are particularly concerned about performance, read through the (short) implementation and benchmark your particular use case. It was adequate for my needs.




MIT. (c) 2013 Agile Diagnosis See