Skip to content

Instantly share code, notes, and snippets.

/**
* Module: function.bind.with-exotic-object-slots
*
* TypeScript declaration for a custom override of `Function.prototype.bind`
* that stores ECMAScript-like internal slot metadata as Symbol-based properties
* on bound functions.
*
* Inspired by ECMAScript internal slots:
* - `[[BoundTargetFunction]]`
* - `[[BoundThis]]`
Symbol.fnDirectives = Symbol.for('fnDirectives');
// const directivesSymbol = Symbol.fnDirectives;
// console.log(Symbol.for(Symbol.keyFor(directivesSymbol)) === Symbol.fnDirectives); // true
const functionPrototype = Function.prototype;
const toFunctionString = functionPrototype.toString;
function parseBodyFromFctString(fctString) {
const [ head ] = fctString
const defaultDescriptorOptions = { enumerable: false, writable: true, configurable: true };
const sealedDescriptorOptions = { enumerable: false, configurable: false };
/**
* Returns the internal `[[Class]]` tag of a value, like `[object String]` or returns `undefined`
* if no argument was passed.
*
* @param {...any} args
* A variadic argument list. The first argument (`args[0]`) is the optional `value` parameter.
* Its **presence** is detected via `args.length`, allowing the function to distinguish between
<!--
// https://stackoverflow.com/questions/78105670/cutom-elements-cant-extend-from-button-illegal-constructor/78106993
//-->
<script>
(function (globalThis) {
// scope of `dom-safari` or `custom-element-safari` module
'use strict';
(function () {
// BEGIN :: module scope
'use strict';
/* function type specifc detection helpers */
/**
* Detects whether a passed function type features a truly `writable`
(function () {
// BEGIN :: module scope
'use strict';
/* function type specifc detection helpers */
/**
* Detects whether a passed function type features a truly `writable`
* `prototype` property.
// a strictly educational deep clone attempt/approach.
function exposeInternalyType(value) {
return Object.prototype.toString.call(value);
}
function isRegExp(value) {
return exposeInternalyType(value) === '[object RegExp]';
}
function isDate(value) {
/**
* - include core-js for enabling/implementing the new `Set` methods
*
* <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.36.0/minified.js"></script>
*
* - for related tasks, like splitting any given keypath most generically into key-partials,
* have a look at ... [https://regex101.com/r/tew8gr/3] ... and its regular expression ...
*
* possible usage:
*
class PausedStateSignal extends EventTarget {
// shared protected/private state.
#state;
constructor(connect) {
super();
this.#state = {
isPaused: false,
};
@petsel
petsel / isDeepStructuralEquality.js
Created January 15, 2024 17:32
modularized approach/implementation for comparing/detecting "Deep Structural Equality".
// utility/helper functions.
function getFunctionName(value) {
return Object.getOwnPropertyDescriptor(value, 'name').value;
// return value.name;
}
function getFunctionSignature(value) {
return Function.prototype.toString.call(value).trim();
}