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. 【转载】Intellij IDEA的Hibernate简单应用

    转载自: https://www.cnblogs.com/yangyquin/p/5438248.html   1.创建数据库及其表 create database demo;    use demo ...

  2. 【转载】CentOS 安装rz和sz命令 lrzsz

    lrzsz在linux里可代替ftp上传和下载.lrzsz 官网入口:http://freecode.com/projects/lrzsz/ lrzsz是一个unix通信套件提供的X,Y,和ZMode ...

  3. BZOJ4756 [USACO17JAN]Promotion Counting晋升者计数

    Description The cows have once again tried to form a startup company, failing to remember from past ...

  4. python爬虫09 | 上来,自己动 !这就是 selenium 的牛逼之处

    作为一个男人 在最高光的时刻 就是说出那句 之后 还不会被人打 ... 虽然在现实生活中你无法这样 但是在这里 就让你体验一番 那种呼风唤雨的感觉 我们之前在爬取某些网站的时候 使用到了一些 pyth ...

  5. (ccf模拟)201709-2公共钥匙盒

    #include <iostream> #include<string> #include <algorithm> #include<sstream> ...

  6. 2013年工作中遇到的20个问题(Bug):161-180

    161.用户表和超级用户分成2个表,很不合理,查询的时候,非常复杂. 162.left join还是很有"市场"的.机构表Org连接User时,想获得user的名字,可能存在,也可 ...

  7. 洛谷 P2633 Count on a tree

    P2633 Count on a tree 题目描述 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中last ...

  8. [Oracle]行列转换(行合并与拆分)

    使用wmsys.wm_concat 实现行合并 在 Oracle  中, 将某一个栏位的多行数据转换成使用逗号风格的一行显示.能够使用函数  wmsys.wm_concat 达成. 这个在上一篇 or ...

  9. _DataStructure_C_Impl:基数排序

    #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #de ...

  10. 【转】selenium自动化测试环境搭建

    转:http://blog.csdn.net/mao1059568684/article/details/17347853 第一步 安装JDK JDk1.7. 下载地址:http://www.orac ...