이전의 question을 약간 수정하면 정확한 사용 사례가 객체를 전달하는 위치 아래에 있는데,이 경우 가장 좋은 해결책은 무엇입니까?객체 유형 변수에 대한 클로저
Product.prototype.list = function(body) {
body.options = {
hostname: endPoints.product,
path: '/applications/' + body.entity.type,
method: 'GET'
};
return remote.request(body)
.then(function(result){
body[body.entity.type] = result;
return body;
});
};
var body = {
entity: {
type: null
}
};
body.entity.type = "coke";
product.list(body)
.then(console.log); //will this have {coke: []} or {pepsi: []}
body.entity.type = "pepsi";
product.list(body)
.then(console.log);
개체 기반 참조를 사용할 때 작동하지 않습니다.이 경우 해결책은 무엇입니까?
가장 좋은 해결책은 작동하는 것입니다. 작동합니까? 그렇다면 - 그것이 최상 *입니다. – zerkms
아니요, 객체 기반 참조를 사용할 때 작동하지 않습니다 – user2727195
여기 'endPoints.product'는 무엇입니까? –