JavaScript面向对象的思想
2010-03-31 21:18
381 查看
JavaScript其本身具有强大的面向对象的功能,以下代码展示了几种常见的使用方式:
<script type="text/javascript">
function object1(name,sex) {
this.name = name;
this.sex = sex;
this.yourname = function(){alert('hello world');};
}
object1.prototype = {
change:function(name) {alert(name);},
myname:function(){alert(this.name);}
}
object1.prototype.mysex = function(){alert("sex is"+this.sex);};
obj = new object1('huanghao',1);
obj.myname();
obj.yourname();
obj.change('ha ha');
obj.mysex();
obj2 = {
name:"huanghao",
tellname:function(name){alert(name+this.name);}
}
obj2.tellname("hello ");
</script>
<script type="text/javascript">
function object1(name,sex) {
this.name = name;
this.sex = sex;
this.yourname = function(){alert('hello world');};
}
object1.prototype = {
change:function(name) {alert(name);},
myname:function(){alert(this.name);}
}
object1.prototype.mysex = function(){alert("sex is"+this.sex);};
obj = new object1('huanghao',1);
obj.myname();
obj.yourname();
obj.change('ha ha');
obj.mysex();
obj2 = {
name:"huanghao",
tellname:function(name){alert(name+this.name);}
}
obj2.tellname("hello ");
</script>
相关文章推荐
- 面向对象的编程思想在javascript中的运用(上)
- javascript面向对象思想做form表单验证 代码很精简哦
- javascript面向对象思想2
- JavaScript面向对象OOP思想Class系统
- 面向对象的编程思想在javascript中的运用(上)
- javascript 面向对象实战思想分享
- 面向对象的编程思想在javascript中的运用(上)
- 面向对象的编程思想在javascript中的运用(上)
- Javascript 中面向对象的思想
- javascript中有趣的面向对象的思想
- javascript高级程序员必须要懂的-----面向对象的思想
- 面向对象的编程思想在javascript中的运用上部
- 面向对象的编程思想在javascript中的运用上部
- JavaScript面向对象的支持(1)
- JavaScript面向对象的支持(3)
- 一个简单的、面向对象的javascript基础框架
- javascript面向对象——tabs实例
- javascript面向对象--继承特性
- JavaScript面向对象之类
- 网站前端_JavaScript-基础入门.0015.JavaScript面向对象