CanJS provides a plethora of utility methods. These methods are usually mapped
to similar methods in the library that underlies CanJS, but for libraries that
do not have the given methods, CanJS provides them for you. This way, you can
create plugins for CanJS that work no matter what library someone else is using.
can.each([{prop: 'foo'}, {prop: 'bar'}], function(element, index) {
// this callback will be called with:
// element = {prop: 'foo'}, index = 0
// element = {prop: 'bar'}, index = 1
});
Object utilites
can.extend extends one object with the properties of another.
var first = {},
second = {a: 'b', c: 'd'},
third = {c: 'e'};
var extended = can.extend(first, second, third);
extended === first; // true
first; // {a: 'b', c: 'e'}
second; // {a: 'b', c: 'd'}
third; // {c: 'e'}
can.param turns an object into a query string.
can.param({a: 'b', c: 'd'}); // 'a=b&c=d'
can.isEmptyObject checks whether an object is empty.
CanJS provides a plethora of utility methods. These methods are usually mapped to similar methods in the library that underlies CanJS, but for libraries that do not have the given methods, CanJS provides them for you. This way, you can create plugins for CanJS that work no matter what library someone else is using.
String utilities
can.trimremoves leading and trailing whitespace.can.escescapes HTML code.can.getObjectlooks up an object by path.can.capitalizecapitalizes a string.can.suballows micro-templating.can.deparamtransforms a form-encoded string into an object..Array utilities
can.makeArrayconverts array-like objects into real Arrays.can.isArraychecks if an object is an Array.can.mapconverts an array into another array using a callback.can.eachiterates through an array.Object utilites
can.extendextends one object with the properties of another.can.paramturns an object into a query string.can.isEmptyObjectchecks whether an object is empty.Function utilites
can.proxyreturns a function that calls another function with a set context.can.isFunctionchecks whether an object is a function.Event utilities
can.bindbinds a callback to an event on an object.can.unbindunbinds a callback from an event on an object.can.delegatebinds a callback to an event on an all elements that match a selector.can.undelegateunbinds a callback from an event on an all elements that match a selector.can.triggertriggers an event on an object.AJAX utilites
can.ajaxwill make an AJAX call and return a Deferred that resolves when the call has returned.Element utilities
can.$creates a library-wrapped NodeList.can.appendappends elements to the elements in a NodeList.