-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
28 lines (20 loc) · 794 Bytes
/
example.js
File metadata and controls
28 lines (20 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var spike = require("./spike.js");
// Dog prototype
var Dog = function(name) { this.name = name; };
Dog.prototype.greet = function() { console.log("Greetings from ", this.name ); };
// Factory function
var createDog = function(breed, name) {
var dog = new Dog(name);
dog.breed = breed;
return dog;
};
// Example for partial
var createDachs = spike.partial(createDog, "dachs");
var dogs = ["Alice", "Bob", "Paula"].map( createDachs );
// Example for prop
console.log("Meet the dogs:", dogs.map( spike.prop("name") ).join(", ") );
// Example for func
dogs.forEach( spike.func("greet") );
// Example for compose
var uppercaseName = spike.compose([ spike.prop("name"), spike.func("toUpperCase") ]);
console.log("Uppercase Name of dogs:", dogs.map( uppercaseName ).join(", ") );