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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:32:13+00:00 2026-06-04T12:32:13+00:00

Basically I need to be able to do this: var obj = {foo:bar}, arr

  • 0

Basically I need to be able to do this:

var obj = {"foo":"bar"},
    arr = [];
with( obj ){
   arr.push( foo );
   arr.push( notDefinedOnObj ); // fails with 'ReferenceError: notDefinedOnObj is not defined'
}
console.log(arr); // ["bar", ""] <- this is what it should be.

I’m looking for a “global” equivalent of {}.__defineGetter__ or {get} in order to return an empty string for all undefined property getters (note that this is different than a property that is undefined).

  • 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-04T12:32:15+00:00Added an answer on June 4, 2026 at 12:32 pm

    You can create a Proxy to return an empty string whenever undefined properties are accessed.

    app.js:

    var obj = {"foo":"bar"},
        arr = [],
        p = Proxy.create({
            get: function(proxy, name) {
                return obj[name] === undefined ? '' : obj[name];
            }
        });
    arr.push( p.foo );
    arr.push( p.notDefinedOnObj );
    
    console.log(arr);
    

    As question author David Murdoch notes, if you are using node v0.6.18 (the latest stable release at the time this post was written), you must pass the --harmony_proxies option when you run the script:

    $ node --harmony_proxies app.js
    [ 'bar', '' ]
    

    Note that this solution will not work if you use with, as in:

    var obj = {"foo":"bar"},
        arr = [],
        p = Proxy.create({
            get: function(proxy, name) {
                return obj[name] === undefined ? '' : obj[name];
            }
        });
    with ( p ) {
       arr.push( foo ); // ReferenceError: foo is not defined
       arr.push( notDefinedOnObj );
    }
    
    console.log(arr);
    

    with does not seem to call the proxy’s get method when adding the proxy to the scope chain.

    Note: the proxy handler passed to Proxy.create() in this is example is incomplete. See Proxy: Common mistakes and misunderstanding for more details.

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

Sidebar

Related Questions

Basically I just need to be able to summon the keyboard whenever a user
I basically need to check if there is an easier way to do this
var links = document.evaluate(//BODY/CENTER[1]/P[1]/TABLE[1]/TBODY[1]/TR[1], document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).evaluate(//A); basically I need to find an element
I'm having a problem with &. Basically I haven't been able to escape this
I basically need to be able to pass through a $q that is a
So basically I need to be able to select the last row to create
I'm using: https://github.com/blueimp/jQuery-File-Upload Basically, I need to be able to save the current done
Basically need to generate custom(some different then yes no) messeges(alert) in JS , how
basically need to change the value that - admin_url() returns any idea?
Basically I need to connect to the database without any existing databases. In SQL,

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.