Problem with CanJS set function

Hi guys, I new in CanJS but when i read article about Map set function i couldn’t realize the example about merge new value into current value. But when i try run the sample, error is appeared: TypeError: this.info is undefined

Sample from https://canjs.com/docs/can.Map.prototype.define.set.html
(in the end of the page)

Contact = can.Map.extend({
  define: {
    info: {
      set: function(newVal){
        this.info.attr(newVal);
        return this.info;
      }
    }
  }
})
var alice = new Contact({
        info: {name: 'Alice Liddell', email: 'alice@liddell.com'}
    });
alice.attr(); // {name: 'Alice Liddell', 'email': 'alice@liddell.com'}
alice.info._cid; // '.map1'
alice.attr('info', {name: 'Allison Wonderland', phone: '888-888-8888'});
alice.attr();
//{
//  name: 'Allison Wonderland',
//  email: 'alice@liddell.com',
//  phone: '888-888-8888'
//}
alice.info._cid; // '.map1'

the docs is maybe wrong.
the sample should look like this:

Contact = can.Map.extend({
  define: {
    info: {
      set: function(newVal){
        if(this.info) {
          return this.info.attr(newVal.serialize());
        }else{
          return newVal
        }
      }
    }
  }
})

see http://jsbin.com/socihinada/edit?html,js,console

3 Likes