_
var f = window.foonyah;
var obj = { a: 1, b: 2, c: 3 };
f.each(obj, function(k, v) {
console.log(k + ':' + v);
return k != 'b';
});
// a:1
// b:2
_
var f = window.foonyah;
var x = Function(), y = {}, z = [];
console.log(f.isFunction(x), f.isFunction(y), f.isFunction(z))
// true, false, false
_
var f = window.foonyah;
var x = Function(), y = {}, z = [];
console.log(f.isArray(x), f.isArray(y), f.isArray(z))
// false, false, true
_
var f = window.foonyah;
var x =null, y = {}, z = new Function();
console.log(f.isPlainObject(x), f.isPlainObject(y), f.isPlainObject(z))
// false, true, false
_
f.typeof(undefined) undefined f.typeof(null) null f.typeof('ABC') string f.typeof(123) number f.typeof(function(){ }) function f.typeof({}) object f.typeof([]) array f.typeof(new f.Emitter()) object var f = window.foonyah;
var x = Function(), y = {}, z = null
console.log(f.type(x), f.type(y), f.type(z))
// function, object, null
_
var f = window.foonyah;
var x = Function();
console.log(f.is('function', x), f.is('object', x), f.is('div', $('<div/>')))
// true, false, true
_
var f = window.foonyah;
console.log(f.noop()());
console.log(f.noop(1)()); // support >= v0.9.3r160314
// undefined
// 1
_
var f = window.foonyah;
var x = $.Deferred();
/* You can use Ecma Script Promise chain after the wrap. */
f.es6promise(x.promise()).then(function(){
return new Promise(function(rsl){
setTimeout(rsl, 3000);
});
})['catch'](fucntion(e){
console.log(e);
});_
var f = window.foonyah;
var x = new Promise(function(rsl){ setTimeout(rsl, 3000) });
/* You can use jQuery.Deferred chain after the wrap. */
f.jquerify(x).pipe(function(){
return $.Deferred().resolve()
}).progress(function(){
console.log(arguments);
});_
var f = window.foonyah;
var ee = new Emitter(); // browser-emitter, implemented by foonyah
/* You can use promise chain for event. */
f.emitterPromise(ee).then(function(r) {
console.log('End Event:', r); // => 1
})['catch']( function(e) { console.log('Error Event:', e) })
setTimeout(function() {
ee.emit('end', 1);
}, 3000)
_
var f = window.foonyah;
var x = function() { console.log('a') }
console.log(f.funcStringify(x));
// console.log('a')
foonyah.each(obj, fn)
Iterate the object ( including <Array> )obj
and execute the functionfn
for each key-value set in the object. The key is give to 1st argument for the functionfn
and the value is given to 2nd argument. If returnfalse
, stop the iterating.foonyah.isFunction(x)
Judge the type ofx
is <Function> or not.foonyah.isArray(x)
Judge the type ofx
is <Array> (NOT including <Object>) or not.foonyah.isPlainObject(x)
Judge the type ofx
is <key-value Object> (NOT including some instance, null) or not.foonyah.type(x)
Return the type ofx
with some extended type compare with JavaScripttypeof
.foonyah.is(type, x)
Judge the type ofx
equalstype
.
Ifx
is an jQuery wrapped object,type
is treated as an selector and returns jQuery.fn.is(type) result.
types are not onlyfoonyah.type
strings but "plainobject" judged byfoonyah.isPlainObject
.foonyah.noop(x)
Returns no-operation function. ( feature: with returnsx
or undefined. )foonyah.es6promise(x)
foonyah.jquerify(x)
foonyah.emitterPromise(x)
> 0.9.10
Wrap event emitter by Ecma Script 6 Promise resolves with the first argument of the last "data" event or last "end", and catch error event then will be rejected.foonyah.funcStringify(fn, replace, options)
Convert a functionfn
to string with using word-mapreplace
.