Path: csiph.com!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.214.226.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: get average height in an object Date: Mon, 13 Nov 2017 03:42:52 +0100 Organization: PointedEars Software (PES) Lines: 122 Message-ID: <2901334.aeNJFYEL58@PointedEars.de> References: <4335673.31r3eYUQgx@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="214.226.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch:178.197.226.214"; logging-data="9180"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.2 X-User-ID: U2FsdGVkX19jMEQDSRMcGEhr1ximHQ7HdG1LbLhZG2waLljAwLERww== 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== Cancel-Lock: sha1:V4qpKoR0GSSBGypi55jMUmQjtfI= X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Thomas 'PointedEars' Lahn wrote: >> Joao Rodrigues wrote: >>> JRough wrote: >>>> This seems like it should be easy enough but I don't get any error >>>> messages in the console. I used jslint and it objects to the >>>> console.log lines >>> >>> This happens because "console" is a browser (and Node.js) feature. >>> However, you may use the /*global*/ directive to "hide" the error in >>> JSLint [1]. For instance: >>> >>> /*global console */ >> >> Too sweeping, unless we are talking about a dedicated debug library. > > Useless remark since I wrote about a JSLint warning. It has nothing to > do with libraries whatsoever. Don't miss the point. *You* are missing the point. If you annotate the code as such, then *all* uses of console.log() will be ignored. This is potentially *detrimental* to code quality. >>> As a side note there are better JS linters such as ESLint and JSHint. >> >> JSHint (which I prefer) will also warn about the undeclared use of >> console.log(). > > Of course ESLint, JSHint and JSLint warn about undeclared use of > 'console' and its methods. JS Linters 101. That is simply untrue. As I have showed, it depends on the configuration. >>>> and it says it needs a semi colon after the data object? >>> Sure does. A semicolon is required in the end of a statement. >> No, in general it is not. > > Nonsense. If semicolons were really optional there would not be a thing > called "Automatic Semicolon Insertion" (ASI) in the Specification, which > states: You have no clue what you are talking about. > "§ 11.9 - Automatic Semicolon Insertion > Certain ECMAScript statements (empty statement, let, const, import, and > export declarations, variable statement, expression statement, debugger > statement, continue statement, break statement, return statement, and > throw statement) *must be terminated with semicolons*." > > Notice the *must be terminated with semicolons* sentence. This is a *specification* mechanism only. > > > Omitting semicolons does not mean they are optional in the Language. Yes, it means exactly that. > Look up the Standard and you will not find the term "optional" for > semicolons. > > ECMAScript Language Specification 101. You have claimed that *source code* would _not_ *work* if it had no semicolons. But because the *script engine* inserts them anyway according to the *language specification*, the *source code* *does* work. Which you would have known if you had actually tried it out. >>>> const data = { >>>> "Matt" : { "height" : 174, "weight": 69 }, >>>> "Jason" : { "height" : 190, "weight": 103 } >>>> } >>> >>> It lacks a semicolon after the "}". > > I was pointing out the position in the OP's source text where they > reported the JSLint warning. So the comment above is valid in the > context of the OP's question. You are missing the point. Your claim was at least misleading. It is _not_ the source code that requires an explicit semicolon there, but an error/warning-free *JSLint* parsing of that source code. Big difference. >>> You don't really need to check for data.hasOwnProperty(key) in this >>> case, because data is a simple dictionary-like object [2]. >> >> Nonsense, and your source does not corroborate your claim. >> >> The value of the “data” constant *variable* here is a reference to an >> Object instance which inherits properties from the object referred to by >> the initial value of Object.prototype > > Prototypal inheritance is a known concept by everyone here. Not to you, obviously. > However, you have *intentionally* omitted the fact that the for...in loop > statement iterates over enumerable properties of an Object, The for-in loop is *irrelevant* to your claim about the object and my counter-argument demonstrating that it is false. > and that's precisely the point here: the hasOwnProperty method is > irrelevant for iterating the Object referenced by the "data" constant > because it hasn't got enumerable properties inherited from Object in the > OP's example. And that is simply wrong. *You cannot know* what enumerable properties it has. And it is certainly not a “dictionary-like object” if its prototype chain is not empty. > Next time, read carefully the OP and subsequent answers before posting > drivel. FOAD. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.