使用外部库实现JavaScript的面向对象特性

2014-06-09
浏览
导读:ECMAScript是通过ECMA-262标准化的脚本程序设计语言,面向对象的JavaScript是对其的扩展和支持。 面向对象语言有能力支持类以及类中方法和属性的重用,在JavaSc

ECMAScript是通过ECMA-262标准化的脚本程序设计语言,面向对象的JavaScript是对其的扩展和支持。

面向对象语言有能力支持类以及类中方法和属性的重用,在JavaScript中实现继承可以通过本身的多种方法来实现,比如call()、 apply()、仿冒、原型链,其中各有优缺点,此外还可以通过一些外部库实现继承的能力,比如xbObject、zinherit等。

◎通过对象仿冒来实现继承:

1. <script type="text/javascript">
2. function Parent(pName){
3.    this.name = pName;
4.    this.sayMyName = function(){
5.       alert(this.name);
6.    };
7. }
8.
9. function Mother(pName){
10.    this.name = pName;
11.    this.sayMyName = function(){
12.       alert(this.name+"sex*y");
13.    };
14. }
15.
16. function Child(cName,cNumber){
17.     this.myFace = Parent;
18.     this.myFace(cName);
19.     delete this.myFace;
20.
21.     this.myFace = Mother;
22.     this.myFace(cName);
23.     delete this.myFace;
24.
25.     this.number = cNumber;
26.     this.sayNumber = function(){
27.       alert(this.number);
28.     };
29. }
30.
31. var ObjP =new Parent("HideHai");
32. var ObjM =new Mother("Hidewow");
33. var ObjC =new Child("HideLow",3);
34.
35. ObjP.sayMyName();
36. ObjM.sayMyName();
37. ObjC.sayMyName();
38. ObjC.sayNumber();
39.   </script>

js代码实现轮播图

js实现上传按钮并显示缩略图小轮子

js实现无缝轮播图特效

Node.js API详解之 os模块用法实例分析

详解react组件通讯方式(多种)