JavaScript Namespace Declaration

后端 未结 8 1919
既然无缘
既然无缘 2020-12-07 15:09

I created a javascript class as follow:

var MyClass = (function() {
   function myprivate(param) {
      console.log(param);
   }

   return {
      MyPublic         


        
8条回答
  •  萌比男神i
    2020-12-07 15:39

    bob.js has nice syntax to define JavaScript namespace:

    bob.ns.setNs('myApp.myMethods', {
        method1: function() {
            console.log('This is method 1');
        },
        method2: function() {
            console.log('This is method 2');
        }
    });
    //call method1.
    myApp.myMethods.method1();
    //call method2.
    myApp.myMethods.method2();
    

提交回复
热议问题