类
bleSdk.js
var age = 28
class bleSdk {
constructor(name) {
console.log("只要new生成实例时,就会自动调用这个函数constructor", name, age)
this.data = {
a: name,
b: {}
}
}
fangfa1() {
console.log("输出111", this.data.a, age)
age = this.data.a
console.log("输出111", this.data.a, age)
}
}
export {
bleSdk
};
在index里面使用:
import {bleSdk} from "../bleSdk"
Page({
data: {
},
onLoad() {
new bleSdk(333).fangfa1()
new bleSdk(444).fangfa1()
},
})
输出:
只要new生成实例时,就会自动调用这个函数constructor 333 28
输出111 333 28
输出111 333 333
只要new生成实例时,就会自动调用这个函数constructor 444 333
输出111 444 333
输出111 444 444