-
-
Save abarrak/3968d01f046c21927b6d55c24181ecb7 to your computer and use it in GitHub Desktop.
JavaScript get caller in strict mode
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
"use strict"; | |
var stackTrace = (new Error()).stack; // Only tested in latest FF and Chrome | |
var callerName = stackTrace.replace(/^Error\s+/, ''); // Sanitize Chrome | |
callerName = callerName.split("\n")[1]; // 1st item is this, 2nd item is caller | |
callerName = callerName.replace(/^\s+at Object./, ''); // Sanitize Chrome | |
callerName = callerName.replace(/ \(.+\)$/, ''); // Sanitize Chrome | |
callerName = callerName.replace(/\@.+/, ''); // Sanitize Firefox | |
console.log(callerName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment