【发布时间】:2019-12-30 04:55:49
【问题描述】:
我正在尝试返回链接对象(列表)的长度。但是,我写的函数没有返回任何东西。
let linkedObject = { value: 1, rest: { value: 2, rest: { value: 3, rest: null } } }
function countDepth(liste, count = 0){
if (liste == null) return count
else {
count ++
liste = liste.rest
countDepth(liste, count)
}
}
console.log(countDepth(linkedObject))```
expected output:
'3'
actual output:
'undefined'
【问题讨论】:
标签: javascript function object scope