Accessing a variable across different scopes in Javascript
问题 var todoList = { todos: [] displayTodos: function () { console.log(this.todos[i].todoText); } addTodo: function (todoText) { this.todos.push({todoText: todoText}); } } This isn't the complete program, but my question is this: In the displayTodos function, how am I able to access todoText (in the console log line)? Shouldn't the todoText variable that's declared in the addToDo function be limited in scope to the function in which it's declared, addToDo? Thanks 回答1: This has to do with the