From c24d3126733cc08605f9c98dbd6ede102945c9ee Mon Sep 17 00:00:00 2001 From: laohan <120936337@qq.com> Date: Fri, 12 Oct 2018 15:12:43 +0800 Subject: [PATCH 1/2] Another primitive assert function --- snippets/isPrimitive.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/isPrimitive.md b/snippets/isPrimitive.md index 900d83d77..ebe691262 100644 --- a/snippets/isPrimitive.md +++ b/snippets/isPrimitive.md @@ -7,7 +7,7 @@ supplying the type using `typeof`. Since `typeof null` evaluates to `'object'`, it needs to be directly compared. ```js -const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null; +const isPrimitive = val => Object(val) !== val; ``` ```js From 321d4fb6516c4f56ca9bc6b7bc0eb747f9f6e3ad Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 16 Oct 2018 11:34:45 +0300 Subject: [PATCH 2/2] Update isPrimitive.md --- snippets/isPrimitive.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snippets/isPrimitive.md b/snippets/isPrimitive.md index ebe691262..9f2550e01 100644 --- a/snippets/isPrimitive.md +++ b/snippets/isPrimitive.md @@ -2,9 +2,7 @@ Returns a boolean determining if the passed value is primitive or not. -Use `Array.prototype.includes()` on an array of type strings which are not primitive, -supplying the type using `typeof`. -Since `typeof null` evaluates to `'object'`, it needs to be directly compared. +Create an object from `val` and compare it with `val` to determine if the passed value is primitive (i.e. not equal to the created object). ```js const isPrimitive = val => Object(val) !== val;