Skip to content

Instantly share code, notes, and snippets.

@satanworker
Created March 21, 2017 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satanworker/569c12bbd390b826166c32f25b9b8940 to your computer and use it in GitHub Desktop.
Save satanworker/569c12bbd390b826166c32f25b9b8940 to your computer and use it in GitHub Desktop.
event.prototype mutation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
</head>
<body>
<div class="for_test">
Tests on this
</div>
<script type="text/javascript">
(function () {
const _prototype = MouseEvent.prototype;
const descriptor = Object.getOwnPropertyDescriptor(MouseEvent.prototype, 'altKey');
Object.defineProperty(MouseEvent.prototype, '_altKey', descriptor);
Object.defineProperty(MouseEvent.prototype, 'altKey', {
get: function () {
console.log(this)
if (this['_altKey']) {
return false
} else {
return true
}
}
})
document.addEventListener('click', (e) => {
console.log(e.altKey, 'e');
})
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment