Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.etla.org!poup.poupinou.org!fdn.fr!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <6079239.H4DsMt3hnF@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Mon, 20 May 2013 13:48:28 +0200 User-Agent: KNode/4.10.2 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 46 NNTP-Posting-Date: 20 May 2013 13:50:17 CEST NNTP-Posting-Host: 4ef6fb71.newsspool2.arcor-online.net X-Trace: DXC=D\CVc20JA9EHlD;3YcB4Fo<]lROoRA8kF]gfN65mC4\:DmnB X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:19840 Andrew Poulos wrote: > A fragment of some code I've been given has this > > if (typeof options.actor !== "undefined") { > actor = options.actor; > } else if (this.actor !== null) { > actor = this.actor; > } > > and jslint complains of the first line that > > "Unexpected 'typeof'. Use '===' to compare directly with undefined." > > but the complaint makes little sense to me. > > Why is typeof unexpected? Probably because Douglas Crockford is wrong. Prior to ECMAScript Ed. 5, when jslint was released, the “undefined” property of the Global Object was already writable, and it was safer to compare against the result of the “typeof” operation. Nowadays, and especially with host objects, there are insufficient good reasons to choose a different approach. > Why is it asking compare the string return with a primitive? Crockford suggests that you write if (options.actor !== undefined) { instead. But this can only be recommended if you can assume that “undefined” is read-only. Ignore jslint. That said, this should probably be written var actor = options.actor || this.actor; See also jsx.array.createComparator(). -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.