0.5.10 • Published 9 years ago

subject v0.5.10

Weekly downloads
76
License
-
Repository
github
Last release
9 years ago

subject Build Status

Some sweet object definition, inheritance and instantiation in functional syntax.

var subject = require('subject');

// define person builder
var person = subject.define({

		// This will be called on instantiation
		initialize: function (data) {
			this.name = data.name;
		},

		// These are simple methods and prototype properties.
		introduceSelf: function () {
			return 'My name is ' + this.name
		},

		walk: function () {
			// 
		}
	});

// instantiate person
var joe = person({ name: 'Joe Smith' });

joe.introduceSelf() // My name is Joe Smith


// define musician builder, which should inherit from person
var musician = person.define({
		// Overwrite initialization
		initialize: function (data) {
			// call the person's
			person.base.initialize.apply(this, arguments);

			this.instruments = data.instrments;
		},

		play: function (instrument) {
			return _.contains(this.instruments, instrument) ? '♬ ♫ ♪ ♩ ♭ La La La' : 'I can\'t play that!';
		}
	});

// instantiate musician
var bob = musician({ name: 'Bob Dylan', instruments: ['guitar', 'voice', 'harmonica'] });

// person methods
bob.introduceSelf()    // My name is Bob Dylan

// musician methods.
bob.play('harmonica')  // ♬ ♫ ♪ ♩ ♭ La La La
bob.play('trumpet')    // I can't play that!
0.5.10

9 years ago

0.5.9

10 years ago

0.5.8

10 years ago

0.5.7

10 years ago

0.5.6

10 years ago

0.5.5

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.4.3

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago