请问这个代码的问题在哪里,好像是作用域的问题,具体的不明白
window.onload = seek;
function preOrder(node){
array.push(node);
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function inOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
array.push(node);
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function postOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
array.push(node);
}
function seek(){
var root = document.getElementById("root");
var array = [];
var pre = document.getElementById("preOrder");
var mid = document.getElementById("inOrder");
var post = document.getElementById("postOrder");
pre.onclick = function(){
preOrder(root);
}
mid.onclick = function(){
inOrder(root);
}
post.onclick = function(){
postOrder(root);
}
}
function preOrder(node){
array.push(node);
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function inOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
array.push(node);
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function postOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
array.push(node);
}
function seek(){
var root = document.getElementById("root");
var array = [];
var pre = document.getElementById("preOrder");
var mid = document.getElementById("inOrder");
var post = document.getElementById("postOrder");
pre.onclick = function(){
preOrder(root);
}
mid.onclick = function(){
inOrder(root);
}
post.onclick = function(){
postOrder(root);
}
}
...全文
相关推荐
js代码-作用域 && 作用域链
在这里,我们将深入探讨这两个概念,并结合实际的`main.js`代码示例进行讲解。首先,我们要明白什么是“作用域”。在JavaScript中,作用域决定了变量和函数的可见性和生命周期。
js代码-(1)作用域链,细节题
在函数外部尝试访问`localVar`会抛出错误,因为它的作用域不包含在当前执行上下文中。`README.txt`文件通常用于存放项目的说明或者代码的简要介绍。
英语学习 提高英语归功于 不能不能明白你们能不明白呢
学习能不不能不能明白你们部门呢你们不能不能明白你们不能明白你们不能不买你们能不能明
javascript执行环境,作用域理解
JavaScript 执行环境和作用域的深层次理解在 JavaScript 中,执行环境和作用域是两个非常重要和基本的概念,理解了这两个概念对于 JavaScript 中很多脚本的运行结果就能明白其中的道理了
如何理解Vue的作用域插槽的实现原理
为了克服这个问题,Vue引入了作用域插槽。作用域插槽允许子组件向父组件传递数据,这样父组件就能根据这些数据自定义插槽的内容。


