better-curry
Advanced tools
Comparing version 1.4.0 to 1.5.0
{ | ||
"name": "better-curry", | ||
"main": "index.js", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"authors": [ | ||
@@ -6,0 +6,0 @@ "Paulo Cesar <email@pocesar.e4ward.com>" |
31
index.js
@@ -348,2 +348,33 @@ (function (root, factory){ | ||
/** | ||
* Delegate all functions, setters, getters and methods, from the original proto | ||
* | ||
* @param {Array} skip | ||
* | ||
* @returns {Delegate} | ||
*/ | ||
Delegate.prototype.all = function(skip){ | ||
var base = this.proto[this.target], k; | ||
if (skip && skip.length) { | ||
for (k in base) { | ||
if (skip.indexOf(k) === -1) { | ||
if (typeof base[k] === 'function') { | ||
this.method(k); | ||
} else { | ||
this.access(k); | ||
} | ||
} | ||
} | ||
} else { | ||
for (k in base) { | ||
if (typeof base[k] === 'function') { | ||
this.method(k); | ||
} else { | ||
this.access(k); | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Setup a setter | ||
@@ -350,0 +381,0 @@ * |
{ | ||
"name": "better-curry", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Forget Function.bind and func.apply(context, arguments), performance matters! For a better curry!", | ||
@@ -31,5 +31,6 @@ "main": "index.js", | ||
"browsers": [ | ||
"ie/6..latest", | ||
"chrome/22..latest", | ||
"firefox/16..latest", | ||
"ie/8..latest", | ||
"chrome/latest", | ||
"firefox/3.5", | ||
"firefox/latest", | ||
"safari/latest", | ||
@@ -36,0 +37,0 @@ "opera/11.0..latest", |
@@ -402,2 +402,47 @@ /*jshint evil:true */ | ||
}); | ||
it('should delegate all setters, getters, methods automatically', function(){ | ||
function getObj(){ | ||
var obj = {}; | ||
obj.request = { | ||
tumble: function(){ | ||
return 'tumble'; | ||
}, | ||
tremble: function(){ | ||
return this.generate; | ||
}, | ||
set generate(val) { | ||
var g = val; | ||
return g; | ||
}, | ||
get generate() { | ||
return true; | ||
}, | ||
value: 1, | ||
ok: { | ||
isTrue: true, | ||
sub: function(){ | ||
} | ||
} | ||
}; | ||
return obj; | ||
} | ||
var obj = getObj(); | ||
var delegated = BetterCurry.delegate(obj, 'request'); | ||
delegated.all(); | ||
expect(obj.tumble()).to.be('tumble'); | ||
expect(obj.tremble()).to.be(true); | ||
expect(obj.generate).to.be(true); | ||
expect(obj.value).to.be(1); | ||
expect(obj.ok).to.eql(obj.request.ok); | ||
obj = getObj(); | ||
delegated = BetterCurry.delegate(obj, 'request'); | ||
delegated.all(['tumble']); | ||
expect(obj.tumble).to.be.an('undefined'); | ||
expect(obj.tremble()).to.be(true); | ||
}); | ||
}); | ||
@@ -411,6 +456,6 @@ }); | ||
} | ||
expect(stuff(1,2,3, [1,2,3])).to.eql([1,2,[3],'a',1,2,3,[1,2,3]]); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
358324
6049