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.trim
removes leading and trailing whitespace.can.esc
escapes HTML code.can.getObject
looks up an object by path.can.capitalize
capitalizes a string.can.sub
allows micro-templating.can.deparam
transforms a form-encoded string into an object..Array utilities
can.makeArray
converts array-like objects into real Arrays.can.isArray
checks if an object is an Array.can.map
converts an array into another array using a callback.can.each
iterates through an array.Object utilites
can.extend
extends one object with the properties of another.can.param
turns an object into a query string.can.isEmptyObject
checks whether an object is empty.Function utilites
can.proxy
returns a function that calls another function with a set context.can.isFunction
checks whether an object is a function.Event utilities
can.bind
binds a callback to an event on an object.can.unbind
unbinds a callback from an event on an object.can.delegate
binds a callback to an event on an all elements that match a selector.can.undelegate
unbinds a callback from an event on an all elements that match a selector.can.trigger
triggers an event on an object.AJAX utilites
can.ajax
will make an AJAX call and return a Deferred that resolves when the call has returned.Element utilities
can.$
creates a library-wrapped NodeList.can.append
appends elements to the elements in a NodeList.