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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:15:31+00:00 2026-05-24T23:15:31+00:00

Could someone guide me how to set my own length for a String ,

  • 0

Could someone guide me how to set my own length for a String, as in "string".length or String("string").length.

Afaik, String is a descendant from Object, and the length assignment probably takes place in the prototype.constructor, as well as in the prototype.__defineSetter__;

Edit:
The motivation is to learn how far javascript in current Browsers can pushed in order to implement one’s own language in it. Operator overloading is my second great concern, which seems is intentionally blocked (i.e. no arguments passed to the operator function).

Some motivation comes from:

http://code.google.com/p/traceur-compiler/


UPDATE:
Addition to new Objects can be locked with:
Object.preventExtensions(String.prototype);

Object.seal(obj)…disallows configurability

Object.freeze(obj)…additionally disallows writing

see here: http://msdn.microsoft.com/en-us/library/ff806191(v=vs.94).aspx#Y240

I guess there may be some way do undo this locking states….

Redefinition could be done like this:

 Object.defineProperty(String, "length", {
        value: 101,
        writable: true,
        enumerable: true,
        configurable: true
    });

However will throw “redefine_disallowed” in Chrome V8.

The JS-engine code that throws the error can be found here under DefineOwnProperty:

http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/v8natives.js?r=8073

  • 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-24T23:15:32+00:00Added an answer on May 24, 2026 at 11:15 pm

    That is not quite possible. Theoretically, this would do the job:

    Object.defineProperties(String.prototype, {
        length: {
            get: function(){ return 1; }
        }
    });
    

    But on Chrome it fails with the error redefine_disallowed.

    I honestly think there is a better solution for your scenario.

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

Sidebar

Related Questions

Could someone write-up a step by step guide to developing a C++ based plugin
Could someone guide in what I need to do? I need to attach a
Could someone please guide me into the right direction for this: I wan to
Could someone please point me to a good beginner guide on safely running SQL
Could someone point me to a guide or some information on building a simple
Could someone direct me to a tutorial or guide me how to track motion
Could someone guide me on what path/steps to take to create a simple bootable
Could someone guide me trough example or an URL to achieve my need. Project
Could some one guide me to create a APS logon token in .Net programmatically?
Could someone recommend any good resources for creating Graphics User Interfaces, preferably in C/C++?

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.