We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 497e249 commit ec08068Copy full SHA for ec08068
src/Object/create/index.ts
@@ -0,0 +1,30 @@
1
+/*
2
+ * @Author: Rainy [https://github.com/rain120]
3
+ * @Date: 2022-01-24 11:43:11
4
+ * @LastEditors: Rainy
5
+ * @LastEditTime: 2022-01-24 11:47:54
6
+ */
7
+
8
+export function create(prop: any, options?: Object) {
9
+ if (!['object', 'function'].includes(typeof prop)) {
10
+ throw new TypeError(`Invalid property with ${prop}`);
11
+ }
12
13
+ const Ctor = function() {};
14
15
+ Ctor.prototype = prop;
16
17
+ // @ts-ignore
18
+ const obj = new Ctor();
19
20
+ if (options) {
21
22
+ Object.defineProperties(obj, options);
23
24
25
+ if (prop === null) {
26
+ obj.__proto__ = null;
27
28
29
+ return obj;
30
+}
0 commit comments