4568380
在Test里面有两个方法,getInfo 与pushSeller,当我在pushSeller中调用getInfo时是为定义错误。请问是作用域得问题吗?谢谢!
function Test() {
this.style = new Xinge.Style(4, 1, 1, 1, 0);
this.getInfo = function (os, flag) {
this.accessId = Number(process.env['XINGE_' + flag +'_' + os + '_ACCESS_ID']);
this.secretKey = process.env['XINGE_' + flag + '_' + os + '_SECRET_KEY'];
this.XingeApp = new Xinge.XingeApp(this.accessId, this.secretKey);
}
this.pushSeller = function (seller_id, title, content) {
console.log(this.getInfo); //在这我可用访问到getInfo
db.query(
"SELECT * FROM seller_admin WHERE seller_id=?", [seller_id],
function (err, seller_admin) {
if (err) {
return console.log(err);
}
if (seller_admin.length) {
for (var i = 0; i < seller_admin.length; i++) {
(function (i) {
db.query(
"SELECT os, pushtoken FROM user WHERE uid =?", [seller_admin[i].uid],
function (err, user) {
if (err) {
return console.log(err);
}
if (user[0].pushtoken) {
if (user[0].os == 'android') {
console.log(user);
this.getInfo('ANDROID', 'SHOP'); //在这里我访问不到getInfo
this.android(user[0].pushtoken, title, content)
}
}
}
);
})(i);
}
}
}
);
}
}