Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39164
| Path | csiph.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!2.eu.feeder.erje.net!feeder.erje.net!news.mb-net.net!open-news-network.org!.POSTED.172.228.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: JavaScript + DOM, type system |
| Date | Fri, 20 Nov 2020 16:53:38 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 37 |
| Message-ID | <1932328.oMNUckLgyt@PointedEars.de> (permalink) |
| References | <DOM-20201119215052@ram.dialup.fu-berlin.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| Injection-Info | gwaiyur.mb-net.net; posting-host="172.228.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch:178.197.228.172"; logging-data="16403"; mail-complaints-to="abuse@open-news-network.org" |
| User-Agent | KNode/4.14.10 |
| Cancel-Lock | sha1:I82AOXR6cNB6G5itQpGPQakdKF8= |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| X-User-ID | U2FsdGVkX19HLet8eIQCwSrTXN0NBXP71iA++NX2EqYgHNL5FlrBfQ== |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Xref | csiph.com comp.lang.javascript:39164 |
Show key headers only | View raw
Stefan Ram wrote: > When "a" is an element, > > a.textContent = 4 > > seems to behave like > > a.textContent = "4" > > , but is there any specification giving the meaning of the > assignment of a number of JavaScript to the textContent > attribute of the DOM? As it is a property that is an implementation of an attribute that is specified to be of type DOMString, its values have to be of a DOMString- compatible type (see other answers). In ECMAScript implementations this type is typically String. So there is typically a setter on the property that converts the value to String (as one can see in the Chrome Dev Tools). AFAIK, this behavior exists since the beginning (Netscape 2.0), even before setters were formally introduced into the language. It happens that the string representation of the Number value 4 (the result of its conversion to String using the “String” function) is "4". But that is nothing to be relied upon. When in doubt, use a value that is already likely compatible to the expected type; in the simplest case, read the property before assigning to it, and use the type of the retrieved value as basis for choosing the type of the assigned value. Note that properties which hold references to objects can have the primitive value “null”, of the Null type, as value as well. -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread
Re: JavaScript + DOM, type system Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-11-20 16:53 +0100
csiph-web