Search code examples
javascriptcanjscanjs-construct

Difference between can.Construct and can.Construct.extend


I am reading CanJS API documentation and came across can.Construct.extend http://canjs.com/docs/can.Construct.extend.html .I know that can.Construct creates a constructor function but not able to figure out the use of can.Construct.extend. Can anybody please explain me the difference between can.Construct and can.Construct.extend. If you can explain it with some example, that would be awesome.

Thanks in Advance


Solution

  • The two are functionally the same. Internally, can.Construct() and all of its derivative classes call extend(). It's all down to stylistic preference: can.Construct() or <something derived from can.Construct>() is slightly shorter but you might confuse it with new <something derived from can.Construct>() which creates a new instance, while using <something derived from can.Construct>.extend() is unambiguous