JSFiddle - React, Tailwind, and code Playground
by tikosar
JavaScript
const a = { x: 1 };
const b = { x: 5 };
function test() {
console.log(this.x);
}
const func1 = test.bind(a);
const func2 = test.bind(b);
const func3 = func2.bind(a);
func1(); //1
func2(); //5
func3(); //1
Function.prototype.myBind = function(obj, ...args) {
return (...otherArgs) => {
return this.apply(obj, [...args, ...otherArgs])
}
}
const func4 = test.myBind(a);
func4()
const func5 = func4.myBind(b)
func5()
const MyComp = ({a}) => {
useEffect(() => {
...
return () => {
clean up...
}
}, [a])
const [age, setAge] = useState(6)
const result = useMemo(() => {
return <Result a={a} />
}, [a])
setAge((oldValue) => newValue)
return (
...(true ? )
)
}
export memo(MyComp, (old, newV) => {})
extends PureComponent