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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:04:57+00:00 2026-06-17T09:04:57+00:00

I am working on a GWT project where the host page has scripts that

  • 0

I am working on a GWT project where the host page has scripts that add properties to String.prototype. The host page scripts rely on the existence of these properties in order to run correctly, so I need to make sure that whenever I pass a string from GWT to “host code”, the extra properties are present in the object.

I thought that by calling $wnd.String in a non-constructor context, the extra properties would be there, but this appears to not be the case. In this mock-GWT setup, for example:

test.html:

<!DOCTYPE html>
<html>
<head>
<script>

String.prototype.myStartsWith = function String_myStartsWith(prefix) {
    prefix = String(prefix);
    return (this.indexOf(prefix) === 0);
};

function onLoad() {
    var iframe = document.createElement("IFRAME");
    iframe.src = "javascript:''";
    iframe.id = "myFrame";
    document.body.appendChild(iframe);
    iframe.contentWindow.location.replace("myFrame.html");
}

</script>
</head>
<body onload="onLoad()">
</body>
</html>

myFrame.html:

<!DOCTYPE html>
<html><head><script>

var $wnd = parent;
var $doc = $wnd.document;

debugger;

</script></head></html>

When execution hits the debugger line, the following results are obtained using the JS debugger console:

> $wnd.String !== String
true

> new $wnd.String("test").myStartsWith === undefined
false

> $wnd.String.prototype.myStartsWith === undefined
false

> $wnd.String("test").myStartsWith === undefined
true

The results are the same in Firefox 18.0, Safari 6.0.2, and Opera 12.12.

The first three are expected, but I did not expect the fourth check, $wnd.String("test").myStartsWith === undefined, to be true.

Why is it that myStartsWith is not available in string objects returned by calling $wnd.String in a non-constructor context?

  • 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-17T09:04:58+00:00Added an answer on June 17, 2026 at 9:04 am

    Why is it that myStartsWith is not available in string objects returned by calling $wnd.String in a non-constructor context?

    Because the non-constructor String function just applies ToString and returns a primitive string value. If you access a property of that, the String constructor of the current global context is used – the one without a modified prototype. So

    $wnd.String("test").myStartsWith
    

    is evaluated to

    "test".myStartsWith
    

    and is equivalent to

    new String($wnd.String("test")).myStartsWith
    

    which is undefined of course.

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

Sidebar

Related Questions

I am working on a project for college that uses GWT, Hibernate and Gilead.
I am working on a project using GWT and Maven that I am including
I'm using GWT-Designer on a GWT project. It has been working well however some
I am currently working on a GWT project where I am displaying an HTML
Someone must know of a working eclipse project for GWT / App Engine datastore
I'm working with a project where I use GWT. There's no problems with it,
I am working on a project with MySQL,Hibernate,Java,GWT I am making an entity class
I'm working on GWT. In my application I want to add a session time
I am currently working on a GWT application that requires report printing. The use
I'm working on a GWT project, and I have a bunch of Java classes

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.