计算机学习积累

----转载有理,转载是想研究,想研究才会看,看了才会有感想,转载后我有时会写一些自己的感受
数据加载中……

js对象的建立


JS真是一门经典脚本语言,近日看一些JS的面向对象编程的文章,记录下来。

1.构建类:
    JS中构建类,其实就是构建类的一个构造方法。如下:
var  Foo  =   function  ()
    {
        
this .name  =   " aaa "
;
        
this .b  =   " bbb "
;
        
this .sayHello  =   function
 ()
        {
            alert(
" welcome:   " + this
.name);
        }
    };
    
var  foo  =   new
 Foo();
    foo.name 
=   " wh "
;
    foo.sayHello();
或者如下:
function A(){           
    
var locate1 = "1oh";    
    
this.locate2 = "2oh";    
    
var method1 = function(){    
        alert(locate1);    
    }    
    
this.method2 = function(){    
        alert(
this.locate2);    
        method1();    
    }                                   
A对象的locate1与method1是private级别的; locate2与method2是public级别的。          

posted on 2007-03-07 17:31 freebird 阅读(280) 评论(0)  编辑  收藏 所属分类: javascript


只有注册用户登录后才能发表评论。


网站导航: