Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:24:44+00:00 2026-06-09T12:24:44+00:00

The self.test() doesn’t get triggered inside http.createServer() : App.prototype.createServer = function(){ var self =

  • 0

The self.test() doesn’t get triggered inside http.createServer():

App.prototype.createServer = function(){
    var self = this;

    var s = http.createServer(function(req,res){

                self.test(); // THIS DOESN`T WORK.

                req.addListener('end',function(){
                    res.writeHead(200,{'Content-Type' : 'application/x-javascript'});

                    self.test(); // THIS DOESN`T WORK.
                });

            });

                 self.test(); // THIS WORKS.
    return s;
};
App.prototype.test = function() {
    console.log('test')
};

If i move it out of http.createServer() it works. Why is this?
this is stored in self which should make it not lose context. What am i missing here?
I can provide extra code and more functions (self.init, etc) if necessary.


UPDATE

Instance:

new App({
    port: 8000
});

Initialization:

function App(options){
    if (! (this instanceof arguments.callee)) {
        return new arguments.callee(arguments);
    }
    var self = this;
    self.settings = {
        port : options.port
    }
    self.init();
};
App.prototype.init = function() {
        var self = this;
        self.server = self.createServer();
        self.server.listen(self.settings.port);
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:24:45+00:00Added an answer on June 9, 2026 at 12:24 pm

    req will emit an end event only if it has a body. GET requests won’t emit it, but POST will.

    Also, you are supposed to call listen to bind your server to a socket. How are you making requests to your server ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This doesn't work well: image_log = gtk.Image() image_log.set_from_file(test.png) self.out_button = gtk.Button() self.out_button.add(image_log) self.err_button =
abstract class base { abstract public function test(); public function run() { self::test(); }
How can it be that this test case import unittest class PropTest(unittest.TestCase): def test(self):
module Test def self.model_method puts this is a module method end end class A
I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
class test: def __init__(self, val): self.val = val self.val.lower() Why doesn't lower() operate on
I created an app that has a self-built photo tool. When I test (Debug
I'm clearly missing something here; why doesn't the File menu get added in this
The following code: class MyClass(): def test(self): self.__x = 0 def __setattr__(self, name, value):
I have strange behaviour in Python/PyMongo. dbh = self.__connection__['test'] first = dbh['test_1'] second =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.