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

  • SEARCH
  • Home
  • 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 6128321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:36:50+00:00 2026-05-23T16:36:50+00:00

I have a file that looks like this: function UserController(){}; UserController.prototype = { theData:

  • 0

I have a file that looks like this:

function UserController(){};

UserController.prototype = {
    theData: [],
    findAll: function(callback) {
        callback( null, this.theData );
     },
    findByID: function(id, callback) {
        var result = null;
        var count = theData.length;
        for (var i = 0; i < count; i++) {
            if (this.theData[i]._id == id) {
                result = this.theData[i];
                break;
            }
        }

        callback(null, result);
    },
    findByName: function(name, callback) {
        var result = null;
        var count = theData.length;

        for (var i = 0; i < count; i++) {
            if (this.theData[i].name == name) {
                result = this.theData[i];
                break;
            }
        };

        callback(null, result);
    },
    save: function(users, callback) {
        var user = null;

        if(typeof(users.length) === 'undefined') {
            users = [users];
        }

        var count = users.length;
        for (var i = 0; i < count; i++) {
            user = users[i];
            user._id = userCounter++;
            user.created_at = new Date();
        };

        callback(null, users);
    }
};

When I inspect the object (based off this), it tells me that it is function UserController(){} and has no methods or properties.

I’ve never used prototyping in Javascript and I can’t see a thing wrong with what I’ve done here. It should be noted that I’m using this with Node.js and Expressjs but I don’t believe that would be causing this problem.

EDIT
For brevity’s sake I only posted what I was currently using, but I have also had the exact same problem using the file like this:

var userCounter = 1;

function UserController(){};

UserController.prototype.theData = [];

UserController.prototype.findAll = function(callback) {
    callback( null, this.theData );
};

UserController.prototype.findByID = function(id, callback) {
    var result = null;
    var count = theData.length;

    for (var i = 0; i < count; i++) {
        if (this.theData[i]._id == id)
        {
            result = this.theData[i];
            break;
        }
    };

    callback(null, result);
};

UserController.prototype.findByName = function(name, callback) {
    var result = null;
    var count = theData.length;

    for (var i = 0; i < count; i++) {
        if (this.theData[i].name == name) {
            result = this.theData[i];
            break;
        }
    };

    callback(null, result);
};

UserController.prototype.save = function(users, callback) {
    var user = null;

    if(typeof(users.length) === 'undefined') {
        users = [users];
    }

    var count = users.length;
    for (var i = 0; i < count; i++) {
        user = users[i];
        user._id = userCounter++;
        user.created_at = new Date();
    };

    callback(null, users);
};

One more edit
If I put this in the same file and Inspect it I get the results I would expect:

function Test(){};

Test.prototype = {
  theData: [],
  hello: function(){
    return "Hello World!";
  }
};

I don’t see the difference and I don’t see an error in my UserController code.

  • 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-05-23T16:36:50+00:00Added an answer on May 23, 2026 at 4:36 pm

    This link helped me figure it out.

    Turns out it WAS a problem with Expressjs. When using another file, you have to specifically call export on methods and objects you want to use with require. Or alternately, you can just call this.blahblah = function(){}; instead of export. Then when you require a file, it automatically turns it into an object.

    EDIT
    I found a different solution. It was as simple as changing my require call to look like this: var userController = new (require('./controllers/user').UserController);
    After that, I can use Prototyped functions and objects just fine which makes the file much more readable and easier to understand.

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

Sidebar

Related Questions

I have a very large file that looks like this (see below). I have
I have a file that looks like this: A B C D E 0
I currently have a function that looks like this: public void AnimateLayoutTransform(object ControlToAnimate) {
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
So I have a a text file that looks something like this: public >ret
Suppose I have a text file that looks like this: 33 3 46 12
Ok..so i have a json string (myJson) that looks like this: {id: 1, file:
I have an xml file that looks like this: <!DOCTYPE ROOT SYSTEM zombie.dtd> <ROOT>
Function cue.getCueAsSource(); gives me a nice and clean JSON file that looks like this:
Is there any way to have something that looks just like a file on

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.