-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
676 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
## 1.0.0 (2019-11-15) | ||
|
||
* feat: 1 init project, 2 add jest, typescript; 3 add instanceof ([14e4bdc](https://github.com/Rain120/awesome-code-implementation/commit/14e4bdc)) | ||
* Initial commit ([f49c21c](https://github.com/Rain120/awesome-code-implementation/commit/f49c21c)) | ||
* feat: 1 init project, 2 add jest, typescript; 3 add instanceof ([14e4bdc](https://github.com/Rain120/awesome-javascript-code-implementation/commit/14e4bdc)) | ||
* Initial commit ([f49c21c](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f49c21c)) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### 原理 | ||
|
||
使用 `Object.prototype.toString` 取得对象的一个内部属性 `[[Class]]`,然后依据这个属性,返回 `"[object Array]"` 字符串作为结果(`ECMA`标准中使用`[[]]`来表示语言内部用到的、外部不可直接访问的属性,称为`内部属性`)。利用这 个方法,再配合 `call`,我们可以取得任何对象的内部属性 `[[Class]]`,然后把类型检测转化为字符串比较,以达到我们的目的。 | ||
|
||
### 参考 | ||
|
||
[绝对准确地确定JavaScript对象是否为数组](http://web.mit.edu/jwalden/www/isArray.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-11-14 19:25:01 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-11-21 19:12:43 | ||
*/ | ||
|
||
import { _isArray } from '.'; | ||
|
||
test('_isArray([]) should true', () => { | ||
expect(_isArray([])).toBe(true); | ||
}); | ||
|
||
test('_isArray([1, 2]) should true', () => { | ||
expect(_isArray([1, 2])).toBe(true); | ||
}); | ||
|
||
test('_isArray({ a: 1 }) should false', () => { | ||
expect(_isArray({ a: 1 })).toBe(false); | ||
}); | ||
|
||
test('_isArray({}) should false', () => { | ||
expect(_isArray({})).toBe(false); | ||
}); | ||
|
||
test('_isArray(null) should false', () => { | ||
expect(_isArray(null)).toBe(false); | ||
}); | ||
|
||
test('_isArray(undefined) should false', () => { | ||
expect(_isArray(undefined)).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-11-14 19:25:01 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-11-21 19:08:54 | ||
*/ | ||
|
||
import { isAbsType } from '../../utils/type'; | ||
|
||
export function _isArray(target: any): boolean { | ||
return isAbsType(target).toLowerCase() === 'array'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
### 原理 | ||
|
||
使用一个指定的 `this` 值和单独给出的一个或多个参数来调用一个函数。 | ||
|
||
### 参考 | ||
|
||
[call](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/call) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-11-21 19:02:37 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-11-21 20:12:23 | ||
*/ | ||
|
||
export function isAbsType(target: any): string { | ||
// [object Object] -> object | ||
return Object.prototype.toString | ||
.call(target) | ||
.split(' ')[1] | ||
.slice(0, -1) | ||
.toLowerCase(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters