Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Object.defineProperties Date: Fri, 05 May 2017 18:14:59 +0200 Organization: PointedEars Software (PES) Lines: 74 Message-ID: <1943190.NgBsaNRSFp@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1494000900 26197 eJwNy8EBwCAIA8CVAEnAcRTK/iPY+x8WlRVO0DGY2nIA9Vu1PqvudOMJhG7y8oyOVYaI3P91Ph0+EPg= (5 May 2017 16:15:00 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 5 May 2017 16:15:00 +0000 (UTC) User-Agent: KNode/4.14.2 X-NNTP-Posting-Host: eJwNxskBwCAIBMCWuHbRciRC/yWYeQ2cyi+DYGAwvjF3dUCUbRl22k+zkDG8wB7tqpB/YinrARRFEH0= Cancel-Lock: sha1:FBAcfW2WmS0xQl9y39rcVnNIgYM= X-User-ID: eJwFwYEBwCAIA7CXLEih5yiT/09YEk6wczO4Y2JGmJvytIdj7otGxKX0Oi+gNmR3g89qlXFlfJJO1xDbfjCzFFI= 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== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. On 03/05/2017 09:24, Stefan Ram wrote: >> Cezary Tomczyk writes: >>> Native built-in Object.defineProperties method allows me to add >>> properties to a function as the function is an object. >> >> The Web gives: >> >> function isObject(val) { >> if (val === null) { return false;} >> return ( (typeof val === 'function') || (typeof val === 'object') ); >> } >> >> . The above might not work with host objects, which might >> have even other types. Correct. But it SHOULD work with newer implementations, see [This *huge* specification has a content filter in the sidebar (now?), which is very handy. It would be better, though, if it were not *only* one huge document.] >> So another suggestion from the Web is: >> >> function isObject(obj) { >> return obj === Object(obj); >> } Nice. But note that this would also designate convertible primitive values “not an object”: isObject(42) === false. >> Other observations: >> >> Object.getPrototypeOf does /not/ throw when called with an object. I beg your pardon? > I use: > > function isTypeOf(obj, typeToCheck) { > if (arguments.length < 2) { > return false; > } > return Object.prototype.toString.call(obj).slice(8, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > -1).toLowerCase() === typeToCheck.toLowerCase(); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > } > > which gives me more precisely a type of object. I hope you have optimized that somewhat. > The Object.defineProperties says about object, but function, array are > also objects. That's why: > > if (typeof obj !== 'object' || obj === null) > throw new TypeError('bad obj'); > > looks like a bug to me. typeof [] === "object", so that is OK. (common misconception) typeof function () {} === "function", so that is not OK in theory; however, one might decide that it is not OK to modify function objects. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.