mass Framework class模块 v11
去掉mutators 对象,它的方法绑到$.factory上,并且它支持继续用户用其他方法定义的“类”
//========================================= // 类工厂模块 v11 by 司徒正美 //========================================== define( "class" , [ "$lang" ], function ( $ ){ var unextend = $.oneObject([ "_super" , "prototype" , 'extend' , 'implement' ]), rconst = /constructor|_init|_super/, classOne = $.oneObject( 'Object,Array,Function' ); function expand(klass,props){ 'extend,implement' .replace( $.rword, function (name){ var modules = props[name]; if ( classOne[ $.type( modules) ] ){ klass[name].apply( klass,[].concat( modules ) ); delete props[name]; } }); return klass; } var hash = { inherit : function ( parent,init ) { var bridge = function () { } if ( typeof parent == "function" ){ for ( var i in parent){ //继承类成员 this [i] = parent[i]; } bridge.prototype = parent.prototype; this .prototype = new bridge ; //继承原型成员 this ._super = parent; //指定父类 if (! this ._init){ this ._init = [parent] } } this ._init = ( this ._init || []).concat(); if ( init ){ this ._init.push(init); } this .toString = function (){ return (init || bridge) + "" } var proto = this .prototype; proto.setOptions = function (){ var first = arguments[0]; if ( typeof first === "string" ){ first = this [first] || ( this [first] = {}); [].splice.call( arguments, 0, 1, first ); } else { [].unshift.call( arguments, this ); } $.Object.merge.apply( null ,arguments); return this ; } return proto.constructor = this ; }, implement: function (){ var target = this .prototype, reg = rconst; for ( var i = 0, module; module = arguments[i++]; ){ module = typeof module === "function" ? new module :module; Object.keys(module).forEach( function (name){ if ( !reg.test(name) ){ target[name] = module[name]; } }, this ); } return this ; }, extend: function (){ //扩展类成员 var bridge = {} for ( var i = 0, module; module = arguments[i++]; ){ $.mix( bridge, module ); } for ( var key in bridge ){ if ( !unextend[key] ){ this [key] = bridge[key] } } return this ; } }; $.factory = function ( obj ){ obj = obj || {}; var parent = obj.inherit //父类 var init = obj.init ; //构造器 delete obj.inherit; delete obj.init; var klass = function () { for ( var i = 0 , init ; init = klass._init[i++]; ){ init.apply( this , arguments); } }; $.mix( klass, hash ).inherit( parent, init ); //添加更多类方法 return expand( klass, obj ).implement( obj ); } $.mix($.factory, hash) return $ }); |
如果您觉得此文有帮助,可以打赏点钱给我支付宝1669866773@qq.com ,或扫描二维码


机器瞎学/数据掩埋/模式混淆/人工智障/深度遗忘/神经掉线/计算机幻觉/专注单身二十五年
标签:
javascript
, mass
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义