Quantcast
Viewing all articles
Browse latest Browse all 3491

Re : Instantiate contsructor with it's classname as string!!

You could put them in a namespace:

  1. can.Control.extend('Controls.MyControl', {});

will automatically create a reference:

  1. window.Controls.MyControl

so you can use dynamic access on the Controls namespace, instead of the global namespace.

And if you are using a module system, e.g. RequireJS or StealJS, you can reduce global pollution even further:

  1. // controls/my_control.js
  2. define(['can/control'], function(Control) {
  3.     return Control.extend('MyControl', {});
  4. });

  5. // controls.js
  6. define(['controls/my_control', 'controls/another_control'], function(MyControl, AnotherControl) {
  7.     return { MyControl: MyControl, AnotherControl: AnotherControl };
  8. });



Viewing all articles
Browse latest Browse all 3491

Trending Articles