javascript - 导出我自己的 Array 原型方法并将其用于不同的文件
问题描述
我知道如何导出函数、类和变量。但是,我找不到任何清楚地解释如何导出原型方法并在不同文件上调用它的来源。如果我有像下面这样的原型方法,我如何在另一个文件上使用它?
//Index.js
Array.prototype.firstItem = function() {
return this[0]
}
export {firstItem} //I know this is wrong but how to do it in similar syntax?
//anotherFile.js
import {firstItem} from './Index.js'
const testArray = ["Thank", "You", "For", "Your", "Answer"]
console.log(testArray.firstItem())
谢谢你的回答
解决方案
推荐阅读
- jupyter-notebook - Jupyter IPython Notebook 中丰富的日志记录输出
- html - CSS:绝对元素嵌套粘性元素
- android - 安卓。带有折叠项目的 RecyclerView
- r - Excel 将多个数据集导出到单个电子表格文件
- python - Python为每个类绘制不同颜色的DataFrame
- python - python将两个压缩列表附加到docx文件中
- aws-api-gateway - 具有 lambda 集成的 aws api 网关:binarytypes 正在将请求的主体转换为 base64,而不仅仅是响应的主体
- mysql - Spring Boot 2.5.3、JdbcBatchItemWriter、RDS 上的 MySql 5.7、java.io.IOException:套接字已关闭
- excel - 在 VBA 中将工作表作为变量引用
- linux - 了解 turbostat 调试模式最大涡轮输出