javascript2014-07-10 07:52:52 2609
类是面向对象编程中很重要的概念,有了它可以帮助我们更好的维护代码,并且就代码模块化,提高我们编码效率以及代码的重用率,随着在javascript中没有类这个概率,但是我们仍然可以模拟出类,从而来实现我们的需求。实现的方式比较多,这里选取一个比较简单易懂的方式演示下。如下代码:
window.onload=function(){ var mJsTestClassOne=new JsTestClassOne(); mJsTestClassOne.jcoVariableA=200; alert(mJsTestClassOne.Reduction()); } function JsTestClassOne(){ this.jcoVariableA=10; this.jcoVariableB=20; this.jcoVariableC=30; this.AddAll=function(){ alert(this.jcoVariableA this.jcoVariableB this.jcoVariableC); } this.Reduction =function(){ alert(this.jcoVariableA-this.jcoVariableB-this.jcoVariableC); } }
如果你是一个程序员,看到new关键字了是不是倍感亲切呢?
彭亚欧个人博客原创文章,转载请注明出处
文章关键词:javascript类 javascript类概念
文章固定链接:https://www.pengyaou.com/legendsz/front/codejs/NzY=.html