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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:31:20+00:00 2026-05-28T18:31:20+00:00

I am trying to build a simple worker function that takes a config of

  • 0

I am trying to build a simple worker function that takes a config of properties to be set in the prototype of a class.

Assume that I declare a function that serves as a class stub:

// declaration of "constructor" to fill data members from passed object
function MyClass (config) {
    for (var key in config)
        this[key] = config[key];
}

NOTE: this itself is a hassle to do each time and I would like a design pattern for the body of this “constructor”.

However, now I want to dynamically set the various prototype members of this “class” in batch as follows:

ExtendPrototype(MyClass, {
    func1 : function (arg1) {
    },

    func2 : function (arg2) {
    },

    ...
});

This way it really looks and feels like a class.

The key is the global function ExtendPrototype, which I try as follows:

function ExtendPrototype (cls, protoconfig) {
    for (var key in protoconfig)
        cls.prototype[key] = protoconfig[key];
}

My question is will this work by treating “prototype” as an object, working exactly internally, truly setting the various prototype members as if I had set the cls.prototype.myfunc = function () as several standalone statements?

Or do I have to do something complicated with “eval” in my ExtendPrototype function?

I know that existing javascript libraries do things like this, but for my own code, I’m trying to write a simple class architecture.

Andy

  • 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-28T18:31:21+00:00Added an answer on May 28, 2026 at 6:31 pm

    This should work as expected. There’s no difference between setting properties with dot notation, to setting them in bracket notation.

    Here’s the fiddle to prove it: http://jsfiddle.net/qrsNj/


    P.S. You shouldn’t have the name of random functions start with an uppercase letter. That’s a convention reserved for object constructors.

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

Sidebar

Related Questions

I'm trying to build a simple Magento Module that needs to connect to the
I'm trying to build a simple jquery plugin that can take selectors as parameters.
I've been trying to build a simple prototype application in Django, and am reaching
I'm been trying to build a simple Carousel effect for a set of photos.
Im trying to build a simple AJAX script that uses a form to send
I am trying to build a simple phonebook in cakephp 2.0 that stores &
I'm trying to build a simple environment check script for my firm's test environment.
I am trying to build a simple booking application for a school presented as
I am trying to build a simple nested html menu using HAML and am
I'm currently trying to build a simple component which should monitor, if the user

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.