[removed] constant properties

后端 未结 4 2028
独厮守ぢ
独厮守ぢ 2021-02-13 20:59

In javascript, can I declare properties of an object to be constant?

Here is an example object:

   var XU = {
      Cc: Components.classes
   };
<         


        
4条回答
  •  既然无缘
    2021-02-13 21:39

    If you are using Javascript 1.5 (in XUL for example), you can use the const keyword instead of var to declare a constant.

    The problem is that it cannot be a property of an object. You can try to limit its scope by namespacing it inside a function.

    (function(){ 
    
    const XUL_CC = Components.classes;
    
    // Use the constant here
    
    })()
    

提交回复
热议问题