收集的几个不错的javascript类小例子 时间:2020-05-12 人气:0 具体功能运行后看效果 添加f1添加f2添加f3 移除f1移除f2移除f3 <script LANGUAGE="JavaScript"> function FunctionArray() { var functions=new Array(); var FA=function (){ for(var i=0;i [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] <script> Function.prototype.concat = function() { var funcs = [this].concat(Array.apply([], arguments)); return function(){ var ret = []; for(var i = 0; i < funcs.length; i++) { var func = funcs[i] instanceof Function ? funcs[i] : new Function(funcs[i]); ret.push(func.apply(this, arguments)); } return ret; } } var a = new Function("return 0"); a=a.concat(function(){return 1}, function(){return 2}, function(){return 3}); alert(a()); </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]顺便贴上winter以前写的东西 winte有空的时候快来帮我加点注释 我加不动了…… <script> </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]一个功能更强大的 新建网页 1 <script language="javascript"> if(typeof asfman == "undefined") asfman = {}; //through below method dispath events should note:addEventListener's eventType should not conflict with method asfman.onMethodExecute = function(obj,method,eventType,beforeMethod,evt) { var old = obj[method] || function(){}; evt = evt || {}; obj[method] = function() { evt.arguments = arguments; beforeMethod && this.dispatchEvent(eventType,evt); old.apply(this,arguments); beforeMethod || this.dispatchEvent(eventType,evt); } } asfman.EventManager = function() { this.dispatchEvent = function(eventType, eventArgs) { eventArgs = eventArgs || {}; var events = this["on"+eventType]; var called = 0; if(events && typeof(events) == "function") events = [events]; if(!eventArgs.type) eventArgs.type = eventType; if(events) { var len=events.length; var capturer=events.capturer; var capturerName=events.capturerName; var evt; for(var i=0;i click on me <script> var obj1 = document.getElementById("test"),obj2 = document.getElementById("test2"); asfman.EventManager.call(obj1); obj1.addEventListener("test",function(){obj2.innerText = " test ";}); obj1.addEventListener("test",function(){alert("test");}); asfman.onMethodExecute(obj1,"onclick","test"); </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容