Is it possible to modify the behavior of functions called inside a closure in js?
Lets say i have this code which i am importing from a library:
<code>// b.js
export const b = () => {
console.log('b')
}
// t.js
import {b} from 'b.js';
export const t = () => {
const c = b;
c();
}
</code>
<code>// b.js
export const b = () => {
console.log('b')
}
// t.js
import {b} from 'b.js';
export const t = () => {
const c = b;
c();
}
</code>
// b.js
export const b = () => {
console.log('b')
}
// t.js
import {b} from 'b.js';
export const t = () => {
const c = b;
c();
}
And inside my code i want to modify the behaviour of b, so that i can modify the functionality of the code.
<code>
import {t} from 't.js';
// Code that modifies b
t();
</code>
<code>
import {t} from 't.js';
// Code that modifies b
t();
</code>
import {t} from 't.js';
// Code that modifies b
t();
Of course this is a very abstract example, what i actually want to do is extend the functionality of web-vitals.
The motivation is to be able to extend onLCP
to track custom elements which use element timings.
6