Created
March 2, 2011 06:35
-
-
Save cms/850560 to your computer and use it in GitHub Desktop.
isStrictFunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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