• Static variables in JavaScript


    function MyClass () { // constructor function
      var privateVariable = "foo";   //NO:obj.privateVariable, MyClass.privateVariable; PS:不属于instance,只能在内部使用;
    this.publicVariable = "bar"; //YES:obj.publicVariable; No:MyClass.publicVariable;
    this.privilegedMethod = function () { //YES:obj.privilegedMethod(); NO:MyClass.privilegedMethod();
    alert(privateVariable); }; } MyClass.prototype.publicMethod
    = function () { //YES: obj.publicMethod();
    alert(
    this.publicVariable); }; MyClass.staticProperty = "baz"; //YES: MyClass.staticProperty; //... var myInstance = new MyClass();
  • 相关阅读:
    二叉堆(最小堆, 最大堆)介绍与实现
    C++ 用变量定义数组
    C++ 用变量定义数组
    053185
    053184
    053183
    053182
    053181
    053180
    oracle prior
  • 原文地址:https://www.cnblogs.com/paul-cheung/p/3228830.html
Copyright © 2020-2023  润新知