函数作为另一个函数 ES5 的 属性
Function as property of another function ES5
没多久写过es5,忘记了。你能帮忙解决这个问题吗?
let mock = {
DynamoDB: function() {
{
send: function() {console.log('sending...')}
}
},
};
然后不工作。
let client = new mock.DynamoDB();
client.send(); // does not write to console
构造函数应分配给 this
的 属性。
let mock = {
DynamoDB: function() {
this.send = function() {
console.log('sending...')
}
}
};
let client = new mock.DynamoDB();
client.send();
您需要使用this
:
let mock = {
DynamoDB: function() {
{
this.send = function send(){
console.log('sending...');
};
}
},
};
let client = new mock.DynamoDB();
client.send();
没多久写过es5,忘记了。你能帮忙解决这个问题吗?
let mock = {
DynamoDB: function() {
{
send: function() {console.log('sending...')}
}
},
};
然后不工作。
let client = new mock.DynamoDB();
client.send(); // does not write to console
构造函数应分配给 this
的 属性。
let mock = {
DynamoDB: function() {
this.send = function() {
console.log('sending...')
}
}
};
let client = new mock.DynamoDB();
client.send();
您需要使用this
:
let mock = {
DynamoDB: function() {
{
this.send = function send(){
console.log('sending...');
};
}
},
};
let client = new mock.DynamoDB();
client.send();