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. shell脚本—基础知识,变量

    shell脚本本质: 编译型语言 解释型语言 shell编程基本过程 1.建立shell文件 2.赋予shell文件执行权限,使用chmod命令修改权限 3.执行shell文件 shell变量: sh ...

  2. PL\SQL(day05)

    PLSQL 1.常用的访问数据库的相关技术 1) plsql 过程化的sql 2) proc/c++ 在c/c++语言中访问oracle数据库的技术 3) ado/odbc vc中访问数据库的技术 4 ...

  3. ecshop中{$lang.}标签的修改

    {$lang.}之类的文字都是在语言包里边定义的,所以要修改这些文字的话,我们只需要修改语言包里的文件.首先需要看一下你使用的语言是哪种,如果是中文的话,修改  languages/zh_cn/com ...

  4. Hibernate事务管理-HibernateTransactionManager-对hibernate session的管理

    由于对SSH还停留在比较初级的应用水平上,今天在遇到一个疑惑时折腾了很久,具体问题是这样的, 有这么一个测试方法, public static void test1() { ApplicationCo ...

  5. 【 Codeforces Round #519 by Botan Investments B】Lost Array

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 不难根据a得到x[0..k-1] 然后再根据a[k+1..n]来验证一下得到的x是否正确就好. [代码] #include <bits ...

  6. 【ACM】bailian_2703_骑车与走路_201307301543

    2703:骑车与走路总时间限制: 1000ms 内存限制: 65536kB 描述 在北大校园里,没有自行车,上课办事会很不方便.但实际上,并非去办任何事情都是骑车快,因为骑车总要找车.开锁.停车.锁车 ...

  7. HDOJ 5421 Victor and String 回文串自己主动机

    假设没有操作1,就是裸的回文串自己主动机...... 能够从头部插入字符的回文串自己主动机,维护两个last点就好了..... 当整个串都是回文串的时候把两个last统一一下 Victor and S ...

  8. HDU 5291(Candy Distribution-差值dp)

    Candy Distribution Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  9. 高可用技术工具包 High Availability Toolkit

    HighAvailabilityToolkit High Availability Toolkit includes several solutions by which achieving arch ...

  10. div内容上下左右居中

    <!-- 遮罩层 --> <div id="test" > <div style="position:absolute;top:50%;le ...