Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27972

Re: Style: new String( "abc" )

From Andreas Bergmaier <andber93@web.de>
Newsgroups comp.lang.javascript
Subject Re: Style: new String( "abc" )
Date 2015-06-03 06:22 +0200
Organization albasani.net
Message-ID <mklvde$db3$1@news.albasani.net> (permalink)
References <new-style-20150602185946@ram.dialup.fu-berlin.de> <mkl000$bif$1@news.albasani.net> <2130550.8QLrkFYiEJ@PointedEars.de> <mkl8h8$17b$1@news.albasani.net> <6829198.rnUjZSozy1@PointedEars.de>

Show all headers | View raw


Thomas 'PointedEars' Lahn schrieb:
> Andreas Bergmaier wrote:
>
>> This should get you started:
>> http://stackoverflow.com/questions/17256182/what-is-the-difference-between-string-literals-and-string-objects-in-javascript
>
> I do not see anything there that substantiates your claim.  Instead, I see
> an answer, <http://stackoverflow.com/a/17256419/855543>, that clearly
> contradicts your claim when it says:
>
> | I'll exemplify with V8 but I assume other engines use similar approaches.
> |
> | A string primitive is parsed to a v8::String object. Hence, methods can be
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^            ^^^^^^
> | invoked directly on it as mentioned by jfriend00.

I'd assume you've read the next two sentences as well?

Yes, primitive strings are represented as C++ objects in V8 - because 
sequences of characters can become quite complex, and you might want to 
intern them and everything. An OOP approach seems suitable here, and I'm 
not even sure whether a std::c_str or char* would match your definition 
of primitive C++ value.
But still, those v8::String objects are primitive JS values, while in 
contrast

| A String object, in the other hand, is parsed to a v8::StringObject
| which extends Object and, apart from being a full fledged object,
| serves as a wrapper for v8::String.

So yes, StringObject objects are C++ objects as well. Understanding the 
difference between those two classes, it is clear that using String 
objects in JS

| has to unbox this v8::StringObject's v8::String before executing the
| method, hence it is slower.

  Bergi

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Style: new String( "abc" ) Andreas Bergmaier <andber93@web.de> - 2015-06-02 21:25 +0200
  Re: Style: new String( "abc" ) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-02 22:27 +0200
    Re: Style: new String( "abc" ) Andreas Bergmaier <andber93@web.de> - 2015-06-02 23:51 +0200
      Re: Style: new String( "abc" ) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-03 01:17 +0200
        Re: Style: new String( "abc" ) Andreas Bergmaier <andber93@web.de> - 2015-06-03 06:22 +0200
          Re: Style: new String( "abc" ) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-03 07:57 +0200
            Re: Style: new String( "abc" ) Andreas Bergmaier <andber93@web.de> - 2015-06-03 18:36 +0200
          Re: Style: new String( "abc" ) John Harris <niam@jghnorth.org.uk.invalid> - 2015-06-03 15:38 +0100

csiph-web