isDataMatchingnamespace
を呼び出す際に、無効な使用方法があるthis
となり、どのようにしてisDataMatchingnamespace
を適切な方法で呼び出すことができますか? this
this
以降の無効な使用である「これの潜在的に無効な使用法」を克服するにはどうすればよいですか?
function Client() {
var namespace = "default";
this.addnamespaceTodata = function(data) {
data.namespace = namespace;
return data;
};
this.isdataMatchingnamespace = function(data) {
return data.namespace === namespace;
};
this.filterdatasBynamespace = function(datas) {
var result = [];
_.forEach(datas, function(data) {
if (this.isdataMatchingnamespace(data)) { // I get potentially invalid usage of this so how to overcome and how to call isDataMatchingnamespace in a proper way?
result.push(data);
}
});
}
}
module.exports = Client;
「このキーワードはどのように機能しますか?」(http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) – Andreas