Skip to content

Instantly share code, notes, and snippets.

@Erutan409
Last active May 7, 2022 01:05
Show Gist options
  • Select an option

  • Save Erutan409/1fd2585bbc8ea5ee3652cbd332e33875 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

@Erutan409

Copy link
Copy Markdown
Author

@binarykitchen I suppose I could.

@binarykitchen

Copy link
Copy Markdown

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

@Erutan409

Copy link
Copy Markdown
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