JS의 기존 코드에 대한 설계 성가심이 있습니다. 코드가 작동하기 때문에 필자는 절대로 그것을 바꿀 서두를 필요가 없지만 아래에 표시된 복제본은 나를 귀찮게합니다. 이 상황을 피하는 통상적 인/권장/공식적인 방법은 무엇입니까? 키/데이터의 중복 방지
var colours={
red:{id:"red", vals:[1,0,0]},
green:{id:"green", vals:[0,1,0]},
grey:{id:"grey", vals:[0.5,0.5,0.5]}
// ...etc
};
// id needs to be known internally within the object - thus it is defined as a property.
// e.g:
colour.prototype.identify(console.log(this.id));
// id also needs to be used externally to find an object quickly.
// e.g:
function getcolour(s){return colours[s];}
// Although this works. It does mean duplicating data, with the theoretical possibility of a mismatch:
var colours={//...
blue:{id:"green", // oh dear...
방법이가 일반적으로 전문가에 의해 처리 될 것이다 :
실제 시스템은 대형/복잡한 금융 시스템은, 그래서 문제를 보여줍니다 가장 기본적인 예로 단순화된다?
가 [lodash]에보고 (HTTPS를 타고 통과 싶습니다 : //lodash.com/) library –