我在过去使用过Prototype.js并且能够编写类uing:
var XEventDesc = Class.create();
XEventDesc.prototype = {
initialize: function(element, eventName, handler, useCapture) {
....................
}
};
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery在Javascript中编写类
你真的需要使用jQuery来创建一个类吗?javascript对象只是一个函数.
var Rectangle = function(width,height) {
//This section is similar to the initialize() method from prototypejs.
this.width = width;
this.height= height;
//Adding a method to an object
this.getArea = function () {
return this.width*this.height;
}
}
var myRect = new Rectangle(3,4);
alert(myRect.getArea()); //Alerts 12
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3940 次 |
| 最近记录: |