Skip to content

Instantly share code, notes, and snippets.

@tautologistics
Created December 20, 2010 17:03
Show Gist options
  • Save tautologistics/748644 to your computer and use it in GitHub Desktop.
Save tautologistics/748644 to your computer and use it in GitHub Desktop.
Example of explicitly names methods for concise exception stack traces
<html>
<head>
<script language="Javascript">
function Example () {}
Example.prototype.NoName = function () {
this.foo();
}
Example.prototype.ShortName = function ShortName () {
this.foo();
}
Example.prototype.FullName = function Example$FullName () {
this.foo();
}
function ExampleDupeMethods () {}
ExampleDupeMethods.prototype.NoName = function () {
Example.prototype.NoName.call(this);
}
ExampleDupeMethods.prototype.ShortName = function ShortName () {
Example.prototype.ShortName.call(this);
}
ExampleDupeMethods.prototype.FullName = function ExampleDupeMethods$FullName () {
Example.prototype.FullName.call(this);
}
var example = new Example();
var exampleDupe = new ExampleDupeMethods();
try {
example.NoName();
} catch (e) {
console.log(e.stack);
}
try {
example.ShortName();
} catch (e) {
console.log(e.stack);
}
try {
example.FullName();
} catch (e) {
console.log(e.stack);
}
try {
exampleDupe.ShortName();
} catch (e) {
console.log(e.stack);
}
try {
exampleDupe.FullName();
} catch (e) {
console.log(e.stack);
}
/*
()@file:///.../example.html:7
@file:///.../example.html:31
ShortName()@file:///.../example.html:10
@file:///.../example.html:37
Example$FullName()@file:///.../example.html:13
@file:///.../example.html:43
ShortName()@file:///.../example.html:10
ShortName()@file:///.../example.html:21
@file:///.../example.html:49
Example$FullName()@file:///.../example.html:13
ExampleDupeMethods$FullName()@file:///.../example.html:24
@file:///.../example.html:55
*/
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment