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. vue实现单页应用demo

    vue + webpack +ES6/7 + axiso + vuex + vue-router构建项目前端,node + express + mongodb 开发后台 项目demo地址 https: ...

  2. 关于MySQL Server影响ASP.NET网站使用的问题:未能加载文件或程序集MySql.Web.v20

    最近开发的ASP.NET MVC 4网站,之前头头说如果遇到装过MySQL的机器就绕着走,还觉得奇怪 嘛,该来的迟早都会来 于是撞上了一台 启动网站再访问,总是出错,提示“未能加载文件或程序集”,名字 ...

  3. 【剑指Offer】47、求1+2+3+4+···+n

      题目描述:   求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C).   解题思路:   本题本身没有太多 ...

  4. 【剑指Offer】17、树的子结构

      题目描述:   输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构)   解题思路:   要查找树A中是否存在和树B结构一样的子树,我们可以分为两步:第一步, ...

  5. CentOS7下安装docker(Docker系列1)

    CentOS7下安装docker 系统要求 为了安装docker,需要准备 64-bit的CentOS 7 删除非官方的Docker包 yum的仓库中有一个很旧的Docker包, 现在Docker官方 ...

  6. Git 基础教程 之 远程仓库

    ①   注册GitHub账号 由于本地Git仓库和GitHub仓库之间的传输是SSH加密的,所以需要一点设置: a, 创建SSH Key         在用户主目录下,看是否有 .ssh 目录,若无 ...

  7. 1、dubbo的概念

    Dubbo是什么? Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点. Dubbo[]是 ...

  8. BZOJ 3218 UOJ #77 A+B Problem (主席树、最小割)

    大名鼎鼎的A+B Problem, 主席树优化最小割-- 调题死活调不对,一怒之下改了一种写法交上去A了,但是改写法之后第4,5个点常数变大很多,于是喜提UOJ全站倒数第三 目前还不知道原来的写法为什 ...

  9. String Boot-thymeleaf使用(四)

    简介 Thymeleaf是面向Web和独立环境的现代服务器端Java模板引擎,能够处理HTML,XML,JavaScript,CSS甚至纯文本.,可以完全替代jsp,也是spring boot官方推荐 ...

  10. 洛谷 P2764 LibreOJ 6002 最小路径覆盖问题

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...