# base-framework

> An object prototype building framework

Latest version **1.0.1** (published 2012-04-21) · 0 weekly downloads

## Install

```sh
npm install base-framework
pnpm add base-framework
yarn add base-framework
bun add base-framework
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2012-04-21 |
| First published | 2012-04-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Charlotte Gore |
| Maintainers | CharlotteGore |
| Keywords | objects, prototyping, framework |

## Links

- npm: https://www.npmjs.com/package/base-framework
- Repository: https://github.com/CharlotteGore/Base
- Homepage: https://CharlotteGore@github.com/CharlotteGore/Base.git
- npm.io page: https://npm.io/package/base-framework

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) 1.3.x

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2012-04-21
- 1.0.0 — 2012-04-21

## README

## The summary

Base is a lightweight framework for creating consistent, highly readable, chainable and inheritable object prototypes in Javascript. This git repo is for an NPM module for use with Node. It can be used in the browser so long as you manually satisfy the [Underscore](http://documentcloud.github.com/underscore/) dependency. You're already using Underscore anyway though, right, so no problem, yeah? 

Shiny!

## The detail

So, here's some examples and stuff.

### Installing

	npm install base-framework

### Example

	// Require base...
	var base = require('base');
 
	// create a base child. Add the default 'init' constructor which is
	// executed automatically when the object is invoked, and another 
	// instance method.

	var MyFactory = base.createChild()
		.AddInstanceMethods({
			init : function( args ){
				this.args = args;
				return this;
			},
			spewArgs : function(){
				console.log(this.args);
			}
		});

	var myInstance = MyFactory({ hello : 'world'}).spewArgs() // outputs {hello : 'world'} to the console

Objects created with `base.createChild()` have a number of static methods which are used to build your factory.

### addInstanceMethods

	var Foo = base.createChild();

	Foo.addInstanceMethods({
		computeSecretOfEverything : function(){
			this.secret = 42;
			return this;
		},
		getSecret : function(){
			return this.secret;
		}
	});

	Bar = Foo();

	Bar.computeSecretOfEverything();
	Bar.getSecret() === 42 // TRUE

When your instance methods return `this` instead of a value, you can chain the methods, jQuery style, instead.

	Bar.computeSecretOfEverything().getSecret();

### addStaticMethods

Static methods are only available on the object created with `base.createChild()`, not an instance.

	var Foo = base.createChild();

	Foo.addStaticMethods({
		secretOfLifeUniverseAndEverything : function(){
			return 42;
		}
	});

	Foo.secretOfLifeTheUniverseAndEverything() === 42 // TRUE

### createChild

Any object created with `base.createChild()` also has the `createChild` method, which means you can create a whole bunch of instance and static methods on one child of base, then inherit (and override) those later on.

	var Horse = base.createChild()
		.AddInstanceMethods({
			name : function(){
				return "Horse"
			},
			legs : function(){
				return 4;
			},
			goFaster : function(){
				this.speed++;
			}
		});

	var Unicorn = Horse.createChild()
		.AddInstanceMethods({
			name : function(){
				return "Unicorn";
			},
			kill : function(){
				// extra functionality available to unicorns
			}
		});

	var uni = Unicorn();
	var bill = Horse();

	uni.legs() === 4 // TRUE
	uni.name() === 'Unicorn' // TRUE
	uni.goFaster() // exists

	bill.kill() // doesn't exist

### Test

	make test

---
_Source: https://npm.io/package/base-framework · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
