Because sometimes you want something like interfaces in JavaScript
JavaScript CoffeeScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
src
test
udefine
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
bower.json
gruntfile.coffee
package.json

README.md

Bodyguard

Build Status Dependency Status devDependency Status

Because sometimes you want something like interfaces in JavaScript

Installation

If you are using Node.js: npm install bodyguard
If you are using Bower: bower install bodyguard (If you also want to save the configuration in your package.json or bower.json add --save to the command.)

Don't use npm or bower? Just grab bodyguard.js from the dist folder and embed it in your application.

Example

JavaScript:

var MyClass = (function() {
  var MyClass = function() {};
  
  MyClass.prototype.a = function() {
    return 5;
  };
  
  MyClass.prototype.b = function() {
    return 6;
  };
  
  MyClass.prototype.c = function() {
    return 7;
  };
})();

var NewClass = bodyguard('NewClass', ['a', 'b'], new MyClass());
// NewClass can now be instantiated and returns an object with a and b bound
// to its prototype

CoffeeScript:

class MyClass
  constructor: ->
  
  a: -> 5
  b: -> 6
  c: -> 7
  
NewClass = bodyguard 'NewClass', ['a', 'b'], new MyClass()
# NewClass can now be instantiated and returns an object with a and b bound
# to its prototype

(Yes, we all know, technically we shouldn't be calling it classes in JavaScript. :) )