Path: csiph.com!.POSTED.204-73-239-109.cust.centrio.cz!not-for-mail From: Cezary Tomczyk Newsgroups: comp.lang.javascript Subject: Re: Object.defineProperties Date: Sun, 7 May 2017 09:42:50 +0200 Organization: csiph.com Internet News Service Message-ID: References: <1943190.NgBsaNRSFp@PointedEars.de> <1592229.TLkxdtWsSY@PointedEars.de> <38321860.ZmDeoRnzTM@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 7 May 2017 07:42:51 +0000 (UTC) Injection-Info: csiph.com; posting-host="204-73-239-109.cust.centrio.cz:109.239.73.204"; logging-data="49005"; mail-complaints-to="admin@kev009.com" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <38321860.ZmDeoRnzTM@PointedEars.de> Xref: csiph.com comp.lang.javascript:33247 On 07/05/2017 02:37, Thomas 'PointedEars' Lahn wrote: > Cezary Tomczyk wrote: > >> function isTypeOf(obj, typeToCheck) { >> var type; >> >> if (arguments.length < 2) { >> throw new Error('[isTypeOf] requires two arguments'); >> } > > You should throw a TypeError or a custom-typed exception (I throw > object.js:jsx.InvalidArgumentError for such). Nice tip. I will use: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError However, optional argument 'lineNumber' there is a bit weird to me as I don't know where the specified fragment of code will be in a production version (after minification) and therefore I can't pass there a line number. > The message is confusing (“Is ‘isTypeOf’ the element of a one-element > array?”) The purpose of that message is to tell you where the message happened, here the '[isTypeOf]' refers to function name, and what happened, here is a message that 'requires two arguments'. -- Cezary Tomczyk http://www.ctomczyk.pl/ https://www.aslint.org/ - Accessibility validation tool