Deutsch English Français Italiano |
<vgq529$2e02$1@cabale.usenet-fr.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!.POSTED!not-for-mail From: Olivier Miakinen <om+news@miakinen.net> Newsgroups: fr.comp.lang.javascript Subject: Re: Indexation des tableaux en js Date: Sun, 10 Nov 2024 12:22:48 +0100 Organization: There's no cabale Lines: 69 Message-ID: <vgq529$2e02$1@cabale.usenet-fr.net> References: <672bcce0$0$28508$426a74cc@news.free.fr> <vggpas$b9p$1@cabale.usenet-fr.net> <vggrin$29gqi$1@dont-email.me> <672ce7d7$0$12934$426a74cc@news.free.fr> <vgirti$2nvn9$1@dont-email.me> <vgkk1k$2i8l$1@cabale.usenet-fr.net> <vgko9b$35kqs$1@dont-email.me> <672ea1f1$0$16817$426a34cc@news.free.fr> <vgngar$3oc57$2@dont-email.me> <vgnium$197m$1@cabale.usenet-fr.net> <6730844c$0$424$426a74cc@news.free.fr> <vgq1vu$2cnv$1@cabale.usenet-fr.net> <vgq2nc$2d19$1@cabale.usenet-fr.net> NNTP-Posting-Host: 200.89.28.93.rev.sfr.net Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: cabale.usenet-fr.net 1731237769 79874 93.28.89.200 (10 Nov 2024 11:22:49 GMT) X-Complaints-To: abuse@usenet-fr.net NNTP-Posting-Date: Sun, 10 Nov 2024 11:22:49 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4 In-Reply-To: <vgq2nc$2d19$1@cabale.usenet-fr.net> Bytes: 4227 Le 10/11/2024 11:42, je mé répondais : > > Bon, je me suis laissé avoir par l'affichage sur <https://runjs.app/play>. Non, en réalité cet affichage était correct. > En réalité, tout index, qu'il soit fourni sous forme de nombre ou sous toute > autre forme, par exemple une chaine de caractères : > − est transformé en nombre s'il peut représenter un nombre entre 0 et 2^32-2 ; > − est transformé en chaine de caractères dans tous les autres cas. La réalité d'après la norme ECMAScript : <https://tc39.es/ecma262/#sec-array-objects> <cit.> 23.1 Array Objects Arrays are exotic objects that give special treatment to a certain class of property names. See 10.4.2 for a definition of this special treatment. </cit.> <https://tc39.es/ecma262/#sec-array-exotic-objects> <cit.> 10.4.2 Array Exotic Objects An Array is an exotic object that gives special treatment to array index property keys (see 6.1.7). A property whose property name is an array index is also called an element. [...] An object is an Array exotic object (or simply, an Array) if its [[DefineOwnProperty]] internal method uses the following implementation, and its other essential internal methods use the definitions found in 10.1. These methods are installed in ArrayCreate. </cit.> <https://tc39.es/ecma262/#sec-object-type> <cit.> 6.1.7 The Object Type [...] The properties of an object are uniquely identified using property keys. A property key is either a String or a Symbol. All Strings and Symbols, including the empty String, are valid as property keys. A property name is a property key that is a String. An integer index is a property name n such that CanonicalNumericIndexString(n) returns an integral Number in the inclusive interval from +0𝔽 to 𝔽(2**53 - 1). An array index is an integer index n such that CanonicalNumericIndexString(n) returns an integral Number in the inclusive interval from +0𝔽 to 𝔽(2**32 - 2). </cit.> Ce que je comprends de tout ça, c'est qu'un Array est un objet « exotique », et que comme tous ces types d'objets il a des propriétés dont le nom est soit un symbole (par exemple « null » ou « true »), soit une chaîne de caractères. J'en comprends aussi qu'il peut avoir au maximum 2^53 propriétés, mais que si l'une de ces propriétés a comme nom une chaine de caractères représentant un nombre entier entre 0 et 2^32-2, alors elle est considérée comme un index numérique et bénéficie alors d'un traitement particulier, comme s'il s'agissait vraiment d'un tableau indexé par des entiers. Et si par exemple on a un index égal à 1 000 000 alors c'est comme si on avait vraiment réservé une taille mémoire de 1 000 001 objets dont les premiers emplacements sont vides. -- Olivier Miakinen