export default () => {
const [value1, setValue1] = setState({ a: 1 });
const [value2, setValue2] = setState({ a: 1});
const handleClick = () => {
value1.a = 2;
setState({ a : 2 });
}
console.log(value1.a, value2.a);
return (
<button onClick = {handleClick}>Click me</button>
)
}
// 点击代码 输出什么
export default () => {
const [value1, setValue1] = setState(1);
const [value2, setValue2] = setState({ a: 1});
const handleClick = () => {
value1 = 2;
setState({ a : 2 });
}
console.log(value1, value2.a);
return (
<button onClick = {handleClick}>Click me</button>
)
}
说说闭包
代码题
function foo() {
let val = 1;
function fn() {
return val;
}
val = 2;
return fn;
}
const fn = foo();
const result = fn(); // 先说代码是怎么执行的,再说结果
function foo() {
let val = 1;
// function fn() {
// return val;
// }
val = 2;
return fn;
}
重写fn, 让result为1;
大概还有一些零碎的问题,只能想到这么多。
#乐言科技#