node package manager



Greenkeeper badge

Build Status

Observable Objects



Create observable objects.

new Map([props])

Creates a new instance of can.Map.

  1. props {Object}: Properties and values to seed the Observe with.
  • returns {can.Map}: An instance of can.Map with the properties from props.

Map.extend([name,] [staticProperties,] instanceProperties)

Creates a new extended constructor function.


Gets a collection of all the properties in this Map.

  • returns {Object}: an object with all the properties in this Map.


Reads a property from this Map.

  1. key {String}: the property to read
  • returns {*}: the value assigned to key.

map.attr(key, value)

Assigns value to a property on this Map called key.

  1. key {String}: the property to set
  2. the {*}: value to assign to key.
  • returns {can.Map}: this Map, for chaining

map.attr(obj[, removeOthers])

Assigns each value in obj to a property on this Map named after the corresponding key in obj, effectively merging obj into the Map.

  1. obj {Object}: a collection of key-value pairs to set. If any properties already exist on the Map, they will be overwritten.

  2. removeOthers {bool}: whether to remove keys not present in obj. To remove keys without setting other keys, use [can.Map::removeAttr removeAttr].

  • returns {can.Map}: this Map, for chaining

map.bind(eventType, handler)

  1. eventType {String}: the type of event to bind this handler to
  2. handler {function}: the handler to be called when this type of event fires The signature of the handler depends on the type of event being bound. See below for details.
  • returns {can.Map}: this Map, for chaining


  1. attrName {String}: the property to bind to
  • returns {can-compute}: a [can-compute] bound to attrName


Specify a default property and value.


A value of any type other than a function that will be set as the DEFAULT-ATTR attribute's value.

map.each( callback(item, propName ) )

each iterates through the Map, calling a function for each property value and key.

  1. callback {function(item, propName)}: the function to call for each property The value and key of each property will be passed as the first and second arguments, respectively, to the callback. If the callback returns false, the loop will stop.
  • returns {can-map}: this Map, for chaining


  1. attrName {String}: the name of the property to remove
  • returns {*}: the value of the property that was removed


Get the serialized Object form of the map. Serialized data is typically used to send back to a server.

o.serialize() //-> { name: 'Justin' }

Serialize currently returns the same data as [can.Map.prototype.attrs]. However, in future versions, serialize will be able to return serialized data similar to [can.Model]. The following will work:

new Map({time: new Date()})
    .serialize() //-> { time: 1319666613663 }
  • returns {Object}: a JavaScript Object that can be serialized with JSON.stringify or other methods.

map.unbind(eventType[, handler])

  1. eventType {String}: the type of event to unbind, exactly as passed to bind
  2. handler {function}: the handler to unbind
var map = new Map({ a: 1 });
function log(){
    console.log("val", map.attr("a");
map.bind("change", log);
map.attr("a", 2);
// Bind callback called. 
map.unbind("change", log);


var people = new Map({
        a: 'Alice',
        b: 'Bob',
        e: 'Eve'
Map.keys(people); // ['a', 'b', 'e'] 
  1. map {can-map}: the Map to get the keys from
  • returns {Array}: array An array containing the keys from map.


Making a Build

To make a build of the distributables into dist/ in the cloned repository run

npm install
node build

Running the tests

Tests can run in the browser by opening a webserver and visiting the test.html page. Automated tests that run the tests from the command line in Firefox can be run with

npm test