If I want to add a prototype to JavaScript's Array
, is there a way to export it so that I can put all of the prototype methods in a file such as modules/prototypes.js
Would it be export Array
? or would I add export prior to setting the prototype?
If your code modifies the global Array.prototype
object (hint: it should not ), you don't need to export anything. You just need to run it. You'd include the module that does this with
import "prototype/array.js";
but not get any particular imports. All arrays would simply inherit from the (now modified) global Array.prototype
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.