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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:39:31+00:00 2026-06-01T21:39:31+00:00

after experimenting with js’s prototypal inheritance i’ve found that i’m not wild about the

  • 0

after experimenting with js’s prototypal inheritance i’ve found that i’m not wild about the idea of having to declare my object’s methods outside of the object:

function obj(){
  this.averyday='i\'m shuffle\'n';
  this.gibmo='dinero';
  this.pullOut='that\'s what she said lol';
}

obj.prototype.alertProp=function(){
    alert(this.averyday);
}
obj.prototype.alertProp2=function(){
    alert(this.gibmo);
}

so i came up with a way to organize my methods into one namespace

obj.prototype.m={
    //i'm passing in the object instance so the mathods can have access to it's properties
    alertProp:function(that){
          alert(that.theObj.everyday);
    },
    alertProp2:function(that){
          alert(that.myObj.gibmo+' '+that.myObj.someVal); // alerts "dinero some other value to be use "
    }
} 
var myobj = new obj;

then to use i just call the method and pass in the objects instance(if the method needs to modify the object’s properties)

myobj.m.alertProp({theObj:myobj,someVal:'some other value to be use'}) //alerts "i'm shuffle'n"

so here are some pros that i’ve noticed:

PROS:

1) organizes the methods into one centralized area.

2) accesses the “prototype” of an object only once(in effect uses less code).

3) seems more readable(at lease to me).

CONS:…this is where i need you’alls help, does anyone see anything wrong with doing it this way? any performance issues or anything wrong with the pros i’ve outlined etc…?

also does anyone see any other pros that i may not be seeing or that aren’t apparent?

  • 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-01T21:39:32+00:00Added an answer on June 1, 2026 at 9:39 pm

    I find it a little bit complicated, this is how I like to do it:

    MyObject = function (options) {
       this.init(options);
    };
    
    MyObject.prototype = {
      /**
       * Documentation
       */
      variable1: null,
    
      init: function (options) {
        // do something with options.
      },
    
      alertVariable: function () {
        alert(this.variable1);
      }
    };
    

    So you don’t have to worry about sending extra parameters, you just call it.

    —————————-EDIT———————————

    Well, I don’t know if I got it right, but after some reading I believe this would “fixing the constructor” mean. If I create an object like this:

    Foo = function () {
      // Do something
    };
    

    Then Foo.prototype.constructor == Foo, as one would expect.
    The problem with my method (thanks Raynos) is that when I’m doing this:

    Foo.prototype = {...};
    

    I’m overwriting all of Foo’s prototype, so that Foo.property.constructor != Foo, and that is not what we would expect! Instead of that we have that Foo.property.constructor == Object.prototype.constructor.

    So, how we fix it?

    Foo.prototype = {
      constructor: Foo, // <-- FIXED!
      ...
    };
    

    Ta da!

    (this helped a lot: http://beej.us/blog/data/javascript-prototypes-inheritance/ )

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

Sidebar

Related Questions

Ok after experimenting a little bit I found out that resin was calling my
After experimenting with scripts on facebook.com, I noticed that for a couple of minutes
I was experimenting with my app in the ios simulator when I found that
After experimenting with an iterator block I noticed the generated IL code is not
After doing some research on the subject, I've been experimenting a lot with patterns
After being stumped by an earlier quesiton: SO google-analytics-domain-data-without-filtering I've been experimenting with a
I am finally experimenting and trying to learn MVC after years of asp.net. I
After reading a few enlightening articles about memory in the .NET technology, Out of
First of all, I'm using Rails 3.1.1 and Ruby 1.9.3-p0 . After experimenting for
After experimenting with composite operations and annotation pdf on the canvas I'm now trying

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.