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 985181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:07:41+00:00 2026-05-16T05:07:41+00:00

I have some simple OO code I’ve written that I’m playing with: //define a

  • 0

I have some simple OO code I’ve written that I’m playing with:

//define a constructor function
function person(name, sex) {
    this.name = name;
    this.sex = sex;

} 

//now define some instance methods
person.prototype.returnName = function() {
    alert(this.name);
}

person.prototype.returnSex = function() {
    return this.sex;
}

person.prototype.talk = function(sentence) {
    return this.name + ' says ' + sentence;
}

//another constructor
function worker(name, sex, job, skills) {
    this.name = name;
    this.sex = sex;
    this.job = job;
    this.skills = skills;
}

//now for some inheritance - inherit only the reusable methods in the person prototype
//Use a temporary constructor to stop any child overwriting the parent prototype 

var f = function() {};
f.prototype = person.prototype;
worker.prototype = new f();
worker.prototype.constructor = worker;

var person = new person('james', 'male');
person.returnName();
var hrTeamMember = new worker('kate', 'female', 'human resources', 'talking');
hrTeamMember.returnName();
alert(hrTeamMember.talk('I like to take a lot'));

Now this is all well and good. But I’m confused. I want to include namespacing as part of my code writing practice. How can I namespace the above code. As it is now I have 2 functions defined in the global namespace.

The only way I can think to do this is to switch to object literal syntax. But then how do I implement the pseudo-classical style above with object literals.

  • 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-16T05:07:42+00:00Added an answer on May 16, 2026 at 5:07 am

    You could for example do following:

    var YourObject;
    if (!YourObject) {
      YourObject = {};
    
      YourObject.Person = function(name, sex) {
        // ...
      } 
    
      YourObject.Person.prototype.returnName = function() {
        // ...
      }
    
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'have written a simple code, that gets accelerometer&orientation meter and display some graphics based
I have written some simple jquery code : function Generate(result, counter) { $(#ArchivesContent).append( <table
I have some simple code: function testing(){ for (a=1; a<=4; a++) { this[btn+a].enabled =
I have some very simple sample code like this: $.ajax({ url: 'demo2.htm', success: function(loadeddata){
I have some very simple sample code like this: $.ajax({ url: 'demo2.htm', success: function(loadeddata){
I have a some simple Java code that looks similar to this in its
I have some simple javascript code that looks like this: var divLink = $(this).attr(href);
I have some very simple javascript code that looks like this: var newWindow =
I have some simple code like this: <?php setcookie(user,test, time() + 3600); echo $_REQUEST['user'].<br>;
I have some simple code in an aspx page <object width=550 height=400> <param name=movie

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.