Static variables in JavaScript

后端 未结 30 2269
别那么骄傲
别那么骄傲 2020-11-22 01:55

How can I create static variables in Javascript?

30条回答
  •  再見小時候
    2020-11-22 02:42

    There is no such thing as an static variable in Javascript. This language is prototype-based object orientated, so there are no classes, but prototypes from where objects "copy" themselves.

    You may simulate them with global variables or with prototyping (adding a property to the prototype):

    function circle(){
    }
    circle.prototype.pi=3.14159
    

提交回复
热议问题