收集的几个不错的javascript类小例子
具体功能运行后看效果
添加f1添加f2添加f3
移除f1移除f2移除f3
function FunctionArray()
{
var functions=new Array();
var FA=function (){
for(var i=0;i
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Function.prototype.concat = function()
{
var funcs = [this].concat(Array.apply([], arguments));
return function(){
var ret = [];
for(var i = 0; i
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
顺便贴上winter以前写的东西
winte有空的时候快来帮我加点注释
我加不动了……
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
一个功能更强大的
新建网页 1
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
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");
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]