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();

Static variables in JavaScript的更多相关文章

  1. Templates and Static variables in C++

    Function templates and static variables: Each instantiation of function template has its own copy of ...

  2. [Testing] Static Analysis Testing JavaScript Applications

    The static code analysis and linting tool ESLint is the de-facto standard for linting JavaScript pro ...

  3. [Training Video - 3] [Groovy in Detail] Non-static and Static variables, objects and object referances

    log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() ...

  4. JavaScript - Scope of variables

    It's important to note, especially if you have come to JavaScript from another language, that variab ...

  5. Learning JavaScript Design Patterns The Singleton Pattern

    The Singleton Pattern The Singleton pattern is thus known because it restricts instantiation of a cl ...

  6. Private Members in JavaScript

    Private Members in JavaScript Douglas Crockford www.crockford.com JavaScript is the world's most mis ...

  7. Attacking JavaScript Engines: A case study of JavaScriptCore and CVE-2016-4622(转)

    转:http://phrack.org/papers/attacking_javascript_engines.html Title : Attacking JavaScript Engines: A ...

  8. Javascript——概述 && 继承 && 复用 && 私有成员 && 构造函数

    原文链接:A re-introduction to JavaScript (JS tutorial) Why a re-introduction? Because JavaScript is noto ...

  9. #Java编程思想笔记(一)——static

    Java编程思想笔记(一)--static 看<Java编程思想>已经有一段时间了,一直以来都把笔记做在印象笔记上,今天开始写博客来记录. 第一篇笔记来写static关键字. static ...

随机推荐

  1. ivew使用星星评分

    这组件好像有问题,不知道是我们项目环境造成的还是什么,初始化半星不能正常显示,显示的全星. 1.template <div style="display:inline-block;ma ...

  2. 金蝶WAFII

  3. Linux基础:seq命令总结

    本文只总结一些常用的用法,更详细的说明见man seq和 seq --help. seq命令 seq命令用于输出数字序列. 语法格式 Usage: seq [OPTION]... LAST or: s ...

  4. marquee图片无缝拼接滚动

    marquee图片无缝滚动 先了解一下对象的几个的属性: innerHTML:     设置或获取位于对象起始和结束标签内的 HTML scrollHeight: 获取对象的滚动高度. scrollL ...

  5. 洛谷P1057 传球游戏【递归+搜索】

    上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:nn个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同学可以把 ...

  6. svn版本库更新后自动同步到www

    注意:www目录一定要用SVN服务器 checkout出Repositories的代码 步骤: (1)新建www根目录 mkdir -p /data/www/lehuo (2)在www根目录下检出(c ...

  7. VirtualBox没有权限访问共享文件夹

    将用户添加至vboxsf组 命令: sudo adduser ly vboxsf 搞定!

  8. 通过winrm使用powershell远程管理服务器

    原文地址 在Linux中,我们可以使用安全的SSH方便的进行远程管理.但在Windows下,除了不安全的Telnet以外,从Windows Server 2008开始提供了另外一种命令行原创管理方式, ...

  9. asp.net--常用的数据库链接字符串

    本地连接 privatestring conn_string ="Data Source=localhost;Initial Catalog=SQLtest;Integrated Secur ...

  10. [hdu 3264] Open-air shopping malls(二分+两圆相交面积)

    题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右 ...