Unicity of custom behavior in a defineMap


Hi !

Still quite new with CanJS, I would like to know how custom behaviors are instantiated.

I tried something :

  • I made a custom behavior, with some parameters,
  • put it in a DefineMap,
  • tried to instantiated it twice (see the JSBin example for concrete informations),

So far so good, but it seems that both defineMap.connection objects are pointing to the same behavior obj …

JSBin example

If someone knows how it works, I would be glad to understand,
Is there a way to achieve this without adding code duplication ?



value should only be set to primitives or a function, otherwise they are shared across all instances. Change it to a function that returns the connection


Thanks for the reply,

Did you means like this ? Because it didn’t work either …


Nope. Not on computer, otherwise I would type. Read docs on value behavior https://canjs.com/doc/can-define.types.value.html#value__


I managed to make what I wanted, thanks for the explanations !