Skip to content

Instantly share code, notes, and snippets.

@Erutan409
Last active May 7, 2022 01:05
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Erutan409/1fd2585bbc8ea5ee3652cbd332e33875 to your computer and use it in GitHub Desktop.
IE Javascript Constructor Name Polyfill
(function () {
if (!Object.constructor.prototype.hasOwnProperty('name')) {
Object.defineProperty(Object.constructor.prototype, 'name', {
get: function () {
return this.toString().trim().replace(/^\S+\s+(\w+)[\S\s]+$/, '$1');
}
})
}
})();
@binarykitchen
Copy link

Nice. Why not put this in a new npm package?

@Erutan409
Copy link
Author

@binarykitchen I suppose I could.

@binarykitchen
Copy link

Thanks for the offer but no need, just realised core-js already has a polyfill. All good.

@Erutan409
Copy link
Author

Yeah, that was my first thought, too, actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment