]> Lady’s Gitweb - Pisces/blob - object.js
502207e3b6ed1f8496300af183e968c9a72e3f9e
[Pisces] / object.js
1 // ♓🌟 Piscēs ∷ object.js
2 // ====================================================================
3 //
4 // Copyright © 2022 Lady [@ Lady’s Computer].
5 //
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
9
10 /** Returns whether the provided value is a constructor. */
11 export const isConstructor = ($) => {
12 if (!isObject($)) {
13 // The provided value is not an object.
14 return false;
15 } else {
16 // The provided value is an object.
17 try {
18 Reflect.construct(
19 function () {},
20 [],
21 $,
22 ); // will throw if $ is not a constructor
23 return true;
24 } catch {
25 return false;
26 }
27 }
28 };
29
30 /** Returns whether the provided value is an object. */
31 export const isObject = ($) => {
32 return $ !== null &&
33 (typeof $ == "function" || typeof $ == "object");
34 };
35
36 /**
37 * Returns whether the provided object inherits from the prototype of
38 * the provided function.
39 */
40 export const ordinaryHasInstance = Function.prototype.call.bind(
41 Function.prototype[Symbol.hasInstance],
42 );
This page took 0.038728 seconds and 3 git commands to generate.