todoList is not Defined (why not?)

The console in plunker and jsFiddle both say that todoList isn’t defined. But it works fine in CodePen. Any thoughts on what I’m doing wrong here?

var todoList = {
  todos: [] ,
  displayAll: function() {
    console.log('My Todos', this.todos);
  addTodo: function(textValue) {
      todoText: textValue,
      completed: false
  changeTodo: function(index, newTextValue) {
    this.todos[index].todoText = newTextValue;
  deleteTodo: function(index) {
    this.todos.splice(index, 1);
todoList.addTodo('new Item');
VM322:1 Uncaught ReferenceError: todoList is not defined(…)(anonymous function) @ VM322:1

It should work. Do you have a link to the jsFiddle that isn’t working?

It seems to work. Where do you see an error?

From my console I’m getting the following error.

Ah, I guess the JS isn’t executed in the global scope. If you put todoList.addTodo('new Item'); inside the JS section and open the console, you will see that it works.

1 Like

thanks. Do you know if there is a drop down in the console to get there?

I was assuming result would be the proper one but that doesn’t appear to be the case.

What are you trying to access?

The javascript scope. (I don’t know jsFiddle all that well but in plunker you should be able to pick the correct context from the drop down - only it’s not working for me in plunker either)

Not sure if this is possible. Anyway, I wouldn’t know how to access it.

1 Like