Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Instantiate contsructor with it's classname as string!!

$
0
0
Do you know a good way to do this ? I mean how to instantiate a class just with it's name as string, I use window global object, but I dont know if it's a good practice!! is can.Construct has a trick around this?
  1. can.Control.extend('MyControl',{
  2.     init:function(el,opts){
  3.         el.html('HOLLA');
  4.     },
  5.     'click':function(el,ev){
  6.         console.log(el);
  7.     }
  8. });
  9. var isFunction=can.isFunction;
  10. can.view.attr('ui-ctrl',function(el,attrData){
  11.     var control=el.getAttribute('ui-ctrl');
  12.     var controlKlass=window[control];
  13.     if(can.isFunction(controlKlass)) {
  14.    new controlKlass(el,{});
  15.     }
  16. });

  17. $('#app').html(can.view('tpl'));

Mohamed Cherif BOUCHELAGHEM

Viewing all articles
Browse latest Browse all 3491

Trending Articles