작은 프로젝트를 진행 중이고 프로젝트의 개체 중 하나에 개체의 속성 인 배열에 업데이트 기능을 추가 할 수 있습니다.자바 스크립트에서 정적 함수 평등을 비교 하시겠습니까?
예 I는 다음처럼 사용할 수있는 위의 코드
/*
Add an update function to the layer
@param function {update} The update to add
*/
Layer.prototype.addUpdate = function (update) {
// Add the update
this.updates.push(update);
};
/*
Remove an update from the layer
@param function {update} The update to remove
*/
Layer.prototype.removeUpdate = function (update) {
this.updates.forEach(function (element, index) {
if (element.toString() === update.toString()) {
this.updates.splice(index, 1);
}
}, this);
};
;
var layer = new Layer();
var func = function() {
x = 10;
};
layer.addUpdate(func);
layer.removeUpdate(func);
그것을 기능 평등을 비교하는이 방법을 수행에 대해 인터넷에서 읽은 후, 사방 읽고는 그렇게 정말 나쁜 것을 말한다.
기능상 실제로 toString()
을 사용하고 있습니까?
업데이트를 추가하거나 제거 할 때 두 매개 변수에 대한 기능 만 제공하는 다른 방법이 있습니까?
UDPATE
2 개 변수는 동일 부호를 가리 있는지 확인하는 방법이 있는가? 보기 (의사);
var a = 10;
var b = a;
var c = a;
if (b and c point to a) //
다른 의견이있는 경우 'toString'이 작동하지 않습니다. –