Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
Last active January 12, 2016 21:54
Show Gist options
  • Save quidmonkey/7b0f20aa74614aa68df8 to your computer and use it in GitHub Desktop.
Save quidmonkey/7b0f20aa74614aa68df8 to your computer and use it in GitHub Desktop.
JavaScript Anonymous Function Call Stack Test in ES5 & ES6
// anonymous function call stack test
// tested and works in chrome, ff, safari, node 4.2.2
// does not work in ie9 or ie11
var f = function f() { g(); };
var g = function g() { h(); };
var h = function h() { console.log(x) };
try {
f();
} catch (e) {
console.error(e);
}
var obj = {
x: 'foo',
y: function () {
console.log(x);
}
}
obj.y();
// anonymous function call stack test
// tested and works in chrome, ff, node 4.2.2
const f = () => g();
const g = () => h();
const h = () => console.log(x);
try {
f();
} catch (e) {
console.error(e);
}
const obj = {
x: 'foo',
y() {
console.log(x);
}
};
obj.y();
<html>
<body>
<script src="anonymous-es5.js"></script>
<script src="anonymous-es6.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment