README
Slim Api
Install
$ npm install --save slim-api
Usage
Return an object instance of an object with only certain feature accessable directly:
var slimApi = require('slim-api');
var original;
var newObj;
function Original() {
this.inventory = 3;
}
Original.prototype.setInventory = function(num) {
this.inventory = num;
}
Original.prototype.getInventory = function() {
return this.inventory;
}
original = new Original();
newObj = slimApi(original, ['setInventory', 'getInventory']);
console.log(newObj.getInventory()) // 3
newObj.setInventory(9)
console.log(newObj.getInventory()) // 9
console.log(newObj.inventory) // undefined
functions can still be applied to other contexts:
var word;
var newObj;
var target;
function Word() {
this.letters = ['t', 'e', 's', 't'];
}
Word.prototype.alphabetize = function () {
return this.letters.sort();
}
word = new Word();
newObj = slimApi(word, ['alphabetize']);
target = {
letters: ['t','a','r','g', 'e', 't']
}
console.log(newObj.alphabetize()) // ['e','s','t','t']
console.log(newObj.alphabetize.call(target)) // ['a','e','g','r','t','t'])