Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Last active October 18, 2017 11:48
Show Gist options
  • Save flying-sheep/fa598de4816dc49598b0168cbc938544 to your computer and use it in GitHub Desktop.
Save flying-sheep/fa598de4816dc49598b0168cbc938544 to your computer and use it in GitHub Desktop.
script insertion and stack traces. jQuery’s magic is bad for debugging
license: mit
<!doctype html>
<head>
<meta charset=utf-8>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
const script = src => {
const node = document.createElement('script')
node.src = src
return node
}
$(() => {
$('head').append(script('test-jquery.js'))
document.head.appendChild(script('test-native.js'))
})
</script>
</head>
<body>
jQuery:
<pre id=jquery></pre>
native:
<pre id=native></pre>
</body>
function bluh() {
throw new Error('where am I?')
}
try {
bluh()
} catch(e) {
document.querySelector('#jquery').textContent = e.stack.toString()
}
function bluh() {
throw new Error('where am I?')
}
try {
bluh()
} catch(e) {
document.querySelector('#native').textContent = e.stack.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment