Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Passing function to other prototype

Passing function to other prototype


I have below code

var Callback = function(op) {
    this.callback = op.callback;

var Test = function (op) {
  for (var option in op) {
    if (!this[option]) this[option] = op[option];


Test.prototype.init = function(bb) {
    console.log('aa = ' + this.aa);
    console.log('bb = ' + bb);

    if (bb 

Line 19 didn't print 'this is finalCallback' AT ALL because this.callback; got executed but it doesn't point to a function. But the below works:


I guess when passing myCallback to myTest, it didn't pass finalCallback??

Can someone help to explain this behavior and how to fix it?

Problem courtesy of: HP.


seems you want to make this (use op.callback as function ):

var Callback = function (op) {
    this.callback = op.callback;
    return this.callback;

and functions should be invoked with ()

 } else {

this is example where it can be used

Solution courtesy of: zb'


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Passing function to other prototype


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription