这里发生了什么事?如果console.log
在内部函数中声明一个变量,则会得到不同的结果
我知道var具有功能范围,内部函数可以从其父级访问变量
function outer() {
var a = 2;
function inner() {
a++;
console.log(a) //log NaN
var a = 8
}
inner()
}
outer()
Run Code Online (Sandbox Code Playgroud)
function outer() {
var a = 2;
function inner() {
a++;
console.log(a) //log 3
var b = 8
}
inner()
}
outer()
Run Code Online (Sandbox Code Playgroud)
NaN
在第一个示例中返回日志3
,在第二个示例中返回日志
我希望我的第一列标题名称接受来自我的 graphql 查询的 2 个数据。
"rocket.rocket_name"
并"links.wikipedia"
显示在渲染 href 上。但似乎 dataIndex 只接受一个字符串。
const { Table, Divider, Tag } = antd;
const columns = [{
title: 'Name',
dataIndex: 'rocket.rocket_name',
key: 'name',
render: text => <a href="www.google.com">{text}</a>,
}, {
title: 'Description',
dataIndex: 'details',
key: 'age',
}];
const data = [
{
"id": "77",
"rocket": {
"rocket_name": "Falcon Heavy",
"rocket": {
"active": true
}
},
"links": {
"wikipedia": "https://en.wikipedia.org/wiki/Arabsat-6A"
},
"details": "SpaceX will launch Arabsat 6A to a geostationary transfer orbit from …
Run Code Online (Sandbox Code Playgroud) 有没有办法更好地理解函数背后的逻辑,而不是仅仅使用它/尝试错误或参考文档?例如 tolist()
我在谷歌上搜索过,没有找到可以参考或重新创建的源代码。我想了解一些功能的基本构建块。或者有什么更好的建议来理解 3rd 方函数/包?
我有一个 Liked 方法,它根据返回值检查数组中的现有项目,组件 Recipe_serving 有条件地显示。我在这里注意到的是,当我将一个项目添加到数组(likedList)子组件重新渲染并检查条件时,但是当我删除项目时,即使使用了 setState 也不会发生重新渲染
class App extends Component {
state = {
result:[],
recipe:{},
isActive:"47746",
addToShopping: [],
likedList:[]
}
setActiveId=(id)=>{
this.getRecipe(id)
}
pushToLikeList = () => {
// if id is in likeList then remove
// if id not in likeList then add
if(this.state.likedList.findIndex(el=>el.recipe.recipe_id===this.state.isActive) === -1){
this.setState(prevState => {
return {
likedList: [prevState.recipe, ...prevState.likedList]
}
})
}else{
this.setState(prevState=>{
const index = prevState.likedList.findIndex(el=>el.recipe.recipe_id===prevState.isActive);
prevState.likedList.splice(index,1)
return{
likedList:prevState.likedList
}
})
}
}
Liked=()=>{
return (this.state.likedList.findIndex(el=>el.recipe.recipe_id===this.state.isActive) !== -1)
}
render() { …
Run Code Online (Sandbox Code Playgroud) 我有一些具有某些属性的对象数组。我想对对象属性做一些数学运算,并希望也返回一个数组。
我试过了,似乎没有用。
array.map(el => {
el.count * 2;
return el
})
Run Code Online (Sandbox Code Playgroud)
array = [{
count: 4,
string: 'randomstring'
}, {
count: 9,
string: 'randomstring'
}, {
count: 7,
string: 'randomstring'
}, {
count: 12,
string: 'randomstring'
}]
Run Code Online (Sandbox Code Playgroud)
预期
array = [{
count: 8,
string: 'randomstring'
}, {
count: 18,
string: 'randomstring'
}, {
count: 14,
string: 'randomstring'
}, {
count: 24,
string: 'randomstring'
}]
Run Code Online (Sandbox Code Playgroud) 为什么即使没有实现 setter 也可以设置二维数组?
这是我的代码。
public static void Main()
{
var obj = new TestObj();
obj.qwe[0, 0] = 6;
obj.asd = 7; //error
Console.WriteLine(obj.qwe[0, 0]); //6
}
public class TestObj
{
public int[,] qwe { get; } = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
public int asd { get; } = 4;
}
Run Code Online (Sandbox Code Playgroud)