Finally found Reflect, which is perfect for me. But it's paid.
Finally found Reflect, which is perfect for me. But it's paid.
The code becomes
console.log('heavy fn');
x = a + 1;
b = memoizedHeavyFn(x);
so I get console log on each rerender, but heavyFn isn't called until x is changed
The code becomes
console.log('heavy fn');
x = a + 1;
b = memoizedHeavyFn(x);
so I get console log on each rerender, but heavyFn isn't called until x is changed
While bind doesn't change the function body, it technically creates a new function, yet still preserves the name property... kinda... by adding a "bound" prefix. #javascript
While bind doesn't change the function body, it technically creates a new function, yet still preserves the name property... kinda... by adding a "bound" prefix. #javascript
Functions aren't cloneable, but you can manually clone them using fn.toString() & new Function() #javascript
No guarantees cloned fn will work, as it may depend on closures or globals. Native functions can't be cloned this way, as toString returns "{ [native code] }"
Functions aren't cloneable, but you can manually clone them using fn.toString() & new Function() #javascript
No guarantees cloned fn will work, as it may depend on closures or globals. Native functions can't be cloned this way, as toString returns "{ [native code] }"
`window.postMessage` uses the structuredClone algorithm to transfer data, and IndexedDB uses it to store data #javascript
`window.postMessage` uses the structuredClone algorithm to transfer data, and IndexedDB uses it to store data #javascript
It doesn't preserve prototype chain for non-builtin object types. #javascript
A Map remains a Map, but MyClass becomes a plain JavaScript object. Null prototype is not preserved too (Object.create(null)).
It doesn't preserve prototype chain for non-builtin object types. #javascript
A Map remains a Map, but MyClass becomes a plain JavaScript object. Null prototype is not preserved too (Object.create(null)).
While DOM nodes aren't cloneable by structuredClone, you can postMessage them between documents by using el.outerHTML to serialize and DOMParser.parseFromString to deserialize
(I have no idea why you'd want to do that) #javascript
While DOM nodes aren't cloneable by structuredClone, you can postMessage them between documents by using el.outerHTML to serialize and DOMParser.parseFromString to deserialize
(I have no idea why you'd want to do that) #javascript
Unlike JSON.stringify & parse:
- It raises exception if any deep prop is non-cloneable (e.g., function or dom node)
- It doesn't offer useful replacer/reviver callbacks
To safely handle arbitrary data, you have to manually traverse it first.
Unlike JSON.stringify & parse:
- It raises exception if any deep prop is non-cloneable (e.g., function or dom node)
- It doesn't offer useful replacer/reviver callbacks
To safely handle arbitrary data, you have to manually traverse it first.