나는 약간의 테스트를 읽고 있었으며 그 명령을 발견했다. 배열의 키가 문자열 인 경우 Array() 자바 스크립트의 "Length"가 작동하지 않습니다. 이 명령을 실행하려면 전체 키를 사용합니다.Array.length가 키 문자열과 함께 작동하지 않는 이유
그러나 내가 왜이 규칙을 말해 줄 수 있는지 궁금합니다. 언어의 제한, 또는 논리의 명세? 아니면, 내 실수 ...?
감사
는것을 제외하고는 내 배열의 핵심은 문자열 (구성 요소의 이름)하지만 값과 객체의 배열입니다 .:.
Declarating :
objElementos = new Array();
대상 :
objElemento = function(Id){
this.Id = $('#' + Id).attr('id');
this.Name = $('#' + Id).attr('name');
this.CssLeft = $('#' + Id).css('left');
this.CssBottom = $('#' + Id).css('bottom');
this.Parent = $('#' + Id).parent().get(0);
this.Childs = new Array();
this.addChild = function(IdObjChild) {
try {
if ($('#' + IdObjChild).attr('id') != '')
this.Childs[$('#' + IdObjChild).attr('id')] = new objElemento(IdObjChild);
} catch(err){ $('#divErrors').prepend('<p>' + err + '</p>'); }
}
this.getChildCount = function(){
try {
$('#divErrors').prepend('<p>' + this.Childs.length + '</p>');
return this.Childs.length;
} catch(err){ $('#divErrors').prepend('<p>' + err + '</p>'); }
}
this.updateCssLeft = function(CssPosition){
try {
$('#divErrors').prepend('<p>updateCssLeft:' + this.Id + '/' + this.CssLeft + '</p>');
$('#' + this.Id).css('left',CssPosition);
this.CssLeft = $('#' + this.Id).css('left');
$('#divErrors').prepend('<p>updateCssLeft:' + this.Id + '/' + this.CssLeft + '</p>');
} catch(err){ $('#divErrors').prepend('<p>' + err + '</p>'); }
}
this.updateCssBottom = function(CssPosition){
try {
$('#divErrors').prepend('<p>updateCssBottom:' + this.Id + '/' + this.CssBottom + '</p>');
$('#' + this.Id).css('bottom',CssPosition);
this.CssBottom = $('#' + this.Id).css('bottom');
$('#divErrors').prepend('<p>updateCssBottom:' + this.Id + '/' + this.CssBottom + '</p>');
} catch(err){ $('#divErrors').prepend('<p>' + err + '</p>'); }
}
}
사용 :
objElementos['snaptarget'] = new objElemento('snaptarget');
그런 다음이 배열을 취급하는 유일한 언어일까요? 나는 자바 스크립트가 객체 지향에서 꽤 불완전하다는 이야기를 들었다. @spender –
많은 다른 언어가 문자열을 사용하여 배열을 색인 할 수 있는지 확신하지 못합니다.하지만 용어 색인이 잘못 적용되었습니다. 사전 형 컬렉션에서는 더 많은 일을합니다. – spender
이제 객체의 배열을 선언하고 요소 (객체)를 추가하고 있습니다. 그렇지 않으면 더 정확하게 할 수 있을까요? - 위의 코드. @spender –