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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:43:05+00:00 2026-06-17T00:43:05+00:00

I have been using the following template to create objects in javascript. function FileSpec(directory,

  • 0

I have been using the following template to create objects in javascript.

function FileSpec(directory, filename){
  var object = {};
  object.full_path = function(){
    return directory + '/' + filename;
  }
  return object;
}

var filespec = FileSpec('tmp', 'index.html');

Are there any particular disadvantages in using the above implementation versus using prototype and new?

function FileSpec(directory, filename){
  this.directory = directory;
  this.filename = filename;
}

FileSpec.prototype.full_path = function(){
  return this.directory + '/' + this.filename
}

var filespec = new FileSpec('tmp', 'index.html');
  • 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-17T00:43:07+00:00Added an answer on June 17, 2026 at 12:43 am
    1. You can’t use the instanceof operator, or the Object.isPrototypeOf() method effectively with 1, but you can with #2.

      filespace instanceof FileSpec; // false with 1, true with 2
      Filespec.isPrototypeOf(filespace); //false with 1, true with 2
      
    2. When using prototype inheritance, prototype members (methods etc) are defined only once on the prototype. In #1, you’re defining a new group of members on each instance, which is more memory intensive.

      var ar = [];
      
      for (var i=0;i<10000000;i++) {
          ar.push(FileSpec('tmp', 'index.html'));
      }
      
      // check memory usage, cry.
      

      Compared to:

      var ar = [];
      
      for (var i=0;i<10000000;i++) {
          ar.push(new FileSpec('tmp', 'index.html'));
      }
      
      // check memory usage.
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following this URL to help me create template views using BrowserView.
I have been using the following sort: var query = _cityRepository.GetAll( .OrderBy(item => item.RowKey.Substring(0,
I have been using the following CSS to apply an effect at the bottom
I have been using the following to add a dynamic link on a page
I am using the following code for the Share Price Application I have been
I have been following the following post on using multiple ItemTemplates in a ListView
I have been doing some research for using MSMQ. Following 2 gave me fundamental
Following the standard instruction for using AES algorithm, I have not been able to
I have been trying to implement a factorial function using the actor model with
I have been using the following code to redirect users to a domain for

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.