![](/img/trans.png)
[英]javascript Module? export default class ? What is it, how do I use it?
[英]How do I export a function from a module for a class that is built into javascript?
我正在嘗試導出一個 function 以在另一個模塊中使用,但它是我添加到字符串 javascript class 中的一個。
我將如何導出 function 以在另一個模塊中使用?
這是我嘗試過的方法,但沒有用
String.prototype.trimChars = function(chars) {...}
export {String}
如何將此 function 作為 trimChars 添加到字符串 class?
您可以簡單地放棄導出,並在另一個模塊中導入。 但是,不建議像這樣修補對象,因為它會引入問題,例如,瀏覽器將新的 function 添加到恰好具有相同名稱的String
。
// in the other module
import "path/to/module.js";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.