There are three main functions of oak. Strapping, extending and exposing.
A strap is a collection of objects that will run against a function. You can strap anything. Think of it as an awesome array.
To strap you call the oak strap function. Any arguments will be added to the strap.
var numbers = ["zero", "one", "two", "three", "four", "five"];
// Expose a strap function
oak.expose({
stringify: function (strap) {
return strap.each(function (item) {
if (oak.isNumber(item)) {
return numbers[item];
}
return item;
});
}
});
// Return ["one", "two" "three", "four", "five"]
var stringified = oak.strap(1, "two", 3, "four", 5);
Extending can be used for creating an options list and even extending a prototype.
// Extending and options list
function setup(opts) {
oak.extend({
font: "Helvetica",
fontSize: 12,
color: "#FFF"
}, opts);
}
setup({
fontSize: 24
});
// Extending prototype
oak.extend(Array.prototype, {
customSort: function () {
// Do something
}
});
Exposing attaches functions to the strap prototype. The first argument of a strap function will always be the strap. Also, you should return the strap whenever possible so your function calls can cascade.
oak.expose({
scale: function (strap, scale) {
return strap.css("transform", "scale(" + scale + ")");
},
backgroundColor: function (strap, color) {
return strap.css("backgroundColor", color;
}
});
oak.strap("div")
.scale(2.0)
.backgroundColor("#00FFFF");