Creating a javascript object with prototyping (no privacy)

后端 未结 4 1771
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 01:27

Can I put similar methods in an associative aray like this?

var function_hold = {   
  function1: function(){}
  function2: function (){}
 };

I

4条回答
  •  不思量自难忘°
    2021-01-29 01:47

    Yes thats possible and works fine.

    Best Practice syntax would be the Module Pattern

    var outerNamespace = {};
    
    (function(ns) {
       // ns is the local name of the object
       ns.function1 = function() {}
       ns.function2 = function() {}
    
      //self executing anonymous function
    } (outerNamespace));
    

提交回复
热议问题