http://www.ruanyifeng.com/blog/2012/07/three_ways_to_define_a_javascript_class.html

 http://www.cnblogs.com/lidabo/archive/2011/12/17/2291238.html

http://www.cnblogs.com/lucas/archive/2009/03/14/1411322.html

 http://www.dreamdu.com/javascript/json/

http://blog.jobbole.com/23563/

http://www.cnblogs.com/lucas/archive/2009/03/14/1411322.html

http://www.phpied.com/3-ways-to-define-a-javascript-class/

  1. 二、定义公有属性和私有字段

function中,用var定义的变量为私有变量,可以理解为类的私有字段。

this定义的变量为公有属性。

     function MyClass() {

        this.id = 5;

        var name = 'myclass...';

     }

 

     my = new MyClass();

     alert(my.id);

     alert(my.name);

     //结果

     // 5

     // undefined

相关文章:

  • 2022-02-19
  • 2021-05-14
  • 2021-12-25
  • 2021-07-10
  • 2021-06-30
  • 2022-01-16
  • 2021-06-15
  • 2021-07-18
猜你喜欢
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
相关资源
相似解决方案