if ( typeof ( fn ) === 'function'
&& fn.name !== ''
&& ar.length > 0 )
{
for ( var i = 0; i < ar.length; i++ )
{
if ( ar[i].name === fn.name )
{
f = true;
break;
}
}
}
return f;
};
// invoke funtions it includes one by one
this.fire = function ( args )
{
if ( ops.once && firedTimes > 0 )
{
return this;
}
if ( ar.length > 0 )
{
var r;
for ( var i = 0; i < ar.length; i++ )
{
r = ar[i].call( this, args );
if ( ops.stopOnFalse && r === false )
{
break;
}
}
}
firedTimes++;
if ( ops.memory )
{
lastArgs = args;
}
return this;
};
};
测试函数如下:(注意fn1 fn2是匿名函数, fn2返回false , fn3是有“名”函数)
复制代码 代码如下:
var fn1 = function ( v )
{
console.log( 'fn1 ' + ( v || '' ) );
};
var fn2 = function ( v )
{
console.log( 'fn2 ' + ( v || '' ) );
return false;
};