文件名称:JavaScript面向对象框架dejavu.js.zip
文件大小:239KB
文件格式:JS
更新时间:2022-08-07 20:13:25
开源项目
dejavu 在JavaScript原型继承的基础上提供了经典的继承形式,使得其他语言开发者可以轻松转向JavaScript。dejavu 主要特性:类(具体的、抽象的、final类)接口混入(这样你可以使用某种形式的多重继承)私有成员和受保护成员静态成员常量函数上下文绑定方法签名检查扩展和借用vanilla类自定义instanceOf,支持接口两个版本:普通版本和AMD优化版本每个版本都有两种模式:严格模式(执行很多检查)和宽松模式(无检查)示例代码:var Person = Class.declare({ // although not mandatory, it's really useful to identify // the class name, which simplifies debugging $name: 'Person', // this is a protected property, which is identified by // the single underscore. two underscores denotes a // private property, and no underscore stands for public _name: null, __pinCode: null, // class constructor initialize: function (name, pinCode) { this._name = name; this.__pinCode = pinCode; // note that we're binding to the current instance in this case. // also note that if this function is to be used only as a // callback, you can use $bound(), which will be more efficient setTimeout(this._logName.$bind(this), 1000); }, // public method (follows the same visibility logic, in this case // with no underscore) getName: function () { return this._name; } _logName: function () { console.log(this._name); } }); 标签:dejavu