Uncaught TypeError: Cannot set property ‘todoText’ of undefined

Working on the Javascript objects and functions. Facing issue with it.

  var todoList = {
      todo:[],
      displayTodo:function(){
        console.log('My Todo:',this.todo); 
      },
      addTodo:function(todoText){
        this.todo.push({
          todoText:todoText,
          complete:false
        });
        this.displayTodo();
      },
      changeTodo:function(posi,newTodo){
        //this.todo[posi] = newTodo; 
        this.todo[posi].todoText=newTodo;
        this.displayTodo();
      },
      toggleComplte:function(posi){
        var todo = this.todo[posi];
        todo.complete = !todo.complete;
        this.displayTodo();
      }
    }


    todoList.toggleComplte(0)

Error I got when running.

VM1196:16 Uncaught TypeError: Cannot set property 'todoText' of undefined
    at Object.changeTodo (<anonymous>:16:29)
    at <anonymous>:21:10

Can some one suggest what is the error ?


Source: stackoverflow-javascript

Available modules in node script

why do I get different results when trying to find out more about the http module in node.js in the following to ways?

  1. If I enter the node REPL and then print the content of the http module, i.e. if I run

    me@mymachine:~> node
    > console.log(http)
    

    I get all the details of the http object:

    { IncomingMessage: { [Function: IncomingMessage] super_: {
    ...
    
  2. If I write a script file called, say, script.js containing the following single line

    console.log(http);
    

    and execute it by running

    node script.js
    

    I get

    ReferenceError: http is not defined
    

I would have expected both cases to behave in the same way – either the http module is preloaded or not. Why is there a difference? What am I getting wrong here?

I thought I could ‘fix’ this by preloading module http by running (in version 2)

node -r http script.js

Shouldn’t this preload module http and thus avoid the reference error?

Looking forward to your input!