Skip to content

Instantly share code, notes, and snippets.

@cms
Created March 2, 2011 06:35
Show Gist options
  • Save cms/850560 to your computer and use it in GitHub Desktop.
Save cms/850560 to your computer and use it in GitHub Desktop.
isStrictFunction
function isStrictFunction(fn) {
if (typeof fn != 'function') throw "Not a function";
try {
fn.caller, fn.arguments;
return false;
} catch (e) {
return e instanceof TypeError;
}
}
(function () {
"use strict";
function fd() {}
console.log(isStrictFunction(fd)); // true
console.log(isStrictFunction(function(){})); // true
console.log(isStrictFunction(Function("'use strict'"))); // true
console.log(isStrictFunction(Function())); // false
console.log(isStrictFunction(isStrictFunction)); // false
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment