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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:40:12+00:00 2026-06-12T10:40:12+00:00

I wish to extend the String class and add a simple method: String.prototype.world =

  • 0

I wish to extend the String class and add a simple method:

String.prototype.world = function(){
  return " world";
} 

and I want to do something like:

"hello".world

and get back "hello world". instead of doing:

"hello".world()

calling a function without brackets will return the function object.

What I’m looking for is to execute the function instead of returning it (without specifying the brackets).

Can I do it somehow in JavaScript?

EDIT: according to this, using __defineGetter__ is non standard and deprecated. looking for alternativs.

  • 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-12T10:40:15+00:00Added an answer on June 12, 2026 at 10:40 am

    You can do that using setter getter. jsfiddle. but setter getter are not supported by IE < 9;

     function getter(){
        return this + " world";
      }
      if(Object.__defineGetter__){ // chrome 
      String.prototype.__defineGetter__('world', getter);
    }else{
     Object.defineProperty(String.prototype, 'world', { // IE
                        get : getter
                    });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish HTML could do something semantically equivalent to this; <dl class=main-list> <definitionitem> <dt>Some
I have a string containing the class name and I wish to get a
I wish to extend a base class in C# with some additional functionality. I
I'm using an API that has a Member class. I wish to extend this
I wish to create a migration whose up method will execute the create_table function.
I wish to do this using only XAML - How to add an additional
I wish to add the mouseover events to a panel which contains more than
I want to develop a task manager like application where I want to display
I asked this question on SO. However, I wish to extend it further. I
I have a simple button class, that when the button is clicked , I

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.