三種定義外部可訪問的方法的形式
阿新 • • 發佈:2021-02-04
技術標籤:微服務線上教育平臺
三種定義外部可訪問的方法的形式
const add = function(a,b){
return parseInt(a)+parseInt(b)
}
module.exports={//定義哪些方法可以被外部訪問
add
}
exports default={
add(){
console.log("lalalala")
}
}
exports.add = function(a,b){
return parseInt(a)+parsrInt(b)
}
訪問時首先需要引入包含外部方法的js檔案
const m = require("./01.js")
m.add() //然後直接呼叫即可