sbiermanlytle / iioEngine

iio Engine: A JavaScript game engine for HTML5 Canvas
http://iioengine.com
455 stars 81 forks source link

Performance: isFunction #29

Closed lcnvdl closed 10 years ago

lcnvdl commented 10 years ago

I'm testing the performance of iio.isFunction in different browsers.

http://jsperf.com/isfunction-performance/2

Tests:

isFunction1 = function(fn) {
    return toString.call(fn) === "[object Function]";
}

isFunction2 = function(fn) {
    return typeof(fn) === "function";
}
isFunction3 = function(fn) {
    return (fn instanceof Function);
}

// iio.isFunction
isFunction4 = function(fn) {
    var getType = {};
    return fn && getType.toString.call(fn) === '[object Function]';
}

Results:

Chrome 35.0.1916

Firefox 31.0

IE 10.0

My recomendation

iio.isFunction = function (fn) {
    return typeof fn === 'function';
}
sbiermanlytle commented 10 years ago

Interesting, I wonder where I found that one.. Thanks for the recommendation, the optimal function has been integrated in 1.3 and added to 1.2