2

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use the varibale "blocks" in callbacks?

daemon.js:

function print(){
    console.log("blocks "+this.blocks);
};

function calc(callback){
    callback();
};

function start(){
    this.print();
};

function start2(){
    this.calc(this.print)
};


var daemon = module.exports = function daemon(options){
    this.blocks = 0;

    this.calc = calc;
    this.print = print;
    this.start = start;
    this.start2 = start2;

};

exports.interface = daemon;

main file:

var daemon = require('./daemon.js');
var d1 = new daemon();
d1.start();
d1.start2();

Output:

blocks 0
blocks undefined

why are there different result for the start-methods?

thank you!

manfred88
  • 21
  • 1

0 Answers0