workerbee

busy bees are srs bees

workerbee

busy bees are srs bees

var workerbee = require("./lib/workerbee");
 
// counter bee 
var counter = workerbee(0, function(){
  return this.value += 1;
});
 
console.log(counter()); // 1 
console.log(counter()); // 2 
console.log(counter()); // 3 
 
 
// random bee 
var random = workerbee({min:10, max:20}, function() {
  return Math.round(Math.random() * (this.max-this.min)) + this.min;
});
 
console.log(random()); // 11 
console.log(random()); // 19 
console.log(random()); // 18 
 
 
// override bee 
var greeter = workerbee(["welcome", "ようこそ", "word is bond"], function(name) {
  return this.value.shift() + "" + name;
});
 
console.log(greeter("bob"));      // welcome, bob 
console.log(greeter("naomi"));    // ようこそ, naomi 
console.log(greeter("mastercj")); // word is bond, mastercj