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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:43:41+00:00 2026-06-04T10:43:41+00:00

I’m quite new to javascript, so maybe it’s a silly error. I created an

  • 0

I’m quite new to javascript, so maybe it’s a silly error.
I created an object like the follwing:

function objA(){
    this.prop1;
    this.prop2;
    this.prop3;
    this.func1=function(){
        alert('func1');
    }
    this.func2=function(){
        alert('func2');
    }
}

I now have a function where I want to pass the object:

var foo=new objA;

function test(foo){....}

The problem is that when I call test(), I get the functions in objA (objA.func1 and objA.func2) executed.
I would like just to get the properties value of objA.
I have to use another function and an array, fill the array with the properties of objA and then pass the array:

var arrayA={}

function fillArray(data){
    arrayA.prop1=data.prop1;
    arrayA.prop2=data.prop2;
    arrayA.prop3=data.prop3;
}

function test(arrayA){....}

Is it the only way or I’m doing something wrong ?

  • 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-04T10:43:42+00:00Added an answer on June 4, 2026 at 10:43 am

    Functions are properties of an object (they are first-class values), and thus they show up in for (var propName in myObj) loops like any other property. You can avoid examining them further via:

    for (var prop in myObj){
      if (!myObj.hasOwnProperty(prop)) continue; // Skip inherited properties
      var val = myObj[prop];
      if (typeof val === 'function'))  continue; // Skip functions
    
      // Must be my own, non-function property
    }
    

    Alternatively, in modern browsers you can make specific properties (like your functions) non-enumerable, so they won’t show up in a for ... in loop:

    function objA(){
      this.prop1 = 42;
      Object.defineProperty(this,'func1',{
        value:function(){
         ...
        }
      });
    }
    

    For more on this, see the docs for Object.defineProperty or Object.defineProperties.

    Finally, if you don’t need to define your functions as closures you can define them on the prototype of your object in which case the hasOwnProperty test will cause them to be skipped:

    function objA(){
      this.prop1 = 42;
    }
    objA.prototype.func1 = function(){
      // operate on the object generically
    };
    
    var a = new objA;
    "func1" in a;              // true
    a.hasOwnProperty("func1"); // false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.