Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Google Chrome "differences"
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gregor Kofler  
View profile  
 More options Sep 3 2008, 5:10 pm
Newsgroups: comp.lang.javascript
From: Gregor Kofler <use...@gregorkofler.at>
Date: Wed, 03 Sep 2008 23:10:04 +0200
Local: Wed, Sep 3 2008 5:10 pm
Subject: Google Chrome "differences"
I've augmented string objects (not the prototype) and none of the
popular browsers ever complained. Until Chrome came along. Chrome won't
accept something like

String.prototype.foo = function() {
   if (!this.bar) {
        this.bar = [];
   }
   // this.bar stays always undefined

}

Trying a workaround I came across

String.prototype.bar = [];

String.prototype.foo = function() {
   this.bar.push({
     o: this,
     p: "baz"
   });
   return this;

}

var x = "foo";
var y = "foo";

x.foo();
y.foo();

alert("".bar[0].o === "".bar[1].o);

yields false in "all" browsers. Chrome returns true.

Any comments on that?

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com  ::: meine JS-Spielwiese
http://www.image2d.com       ::: Bildagentur für den alpinen Raum


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lasse Reichstein Nielsen  
View profile  
 More options Sep 4 2008, 12:48 pm
Newsgroups: comp.lang.javascript
From: Lasse Reichstein Nielsen <lrn.unr...@gmail.com>
Date: Thu, 04 Sep 2008 18:48:58 +0200
Local: Thurs, Sep 4 2008 12:48 pm
Subject: Re: Google Chrome "differences"

Gregor Kofler <use...@gregorkofler.at> writes:
> I've augmented string objects (not the prototype) and none of the
> popular browsers ever complained. Until Chrome came along. Chrome
> won't accept something like

> String.prototype.foo = function() {
>    if (!this.bar) {
>    this.bar = [];
>    }
>    // this.bar stays always undefined
> }

... and ...

> yields false in "all" browsers. Chrome returns true.

> Any comments on that?

Well spotted.
It's not standard-compliant.

It's a lousy standard at that point - requireing the creation of a new
object every time you access a property of a basic string value
... like the *length*! - but still, it is the spec.

/L
--
Lasse Reichstein Nielsen
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lasse Reichstein Nielsen  
View profile  
 More options Sep 4 2008, 1:11 pm
Newsgroups: comp.lang.javascript
From: Lasse Reichstein Nielsen <lrn.unr...@gmail.com>
Date: Thu, 04 Sep 2008 19:11:42 +0200
Local: Thurs, Sep 4 2008 1:11 pm
Subject: Re: Google Chrome "differences"

Gregor Kofler <use...@gregorkofler.at> writes:
> I've augmented string objects (not the prototype) and none of the
> popular browsers ever complained. Until Chrome came along. Chrome
> won't accept something like

> String.prototype.foo = function() {
>    if (!this.bar) {
>    this.bar = [];
>    }
>    // this.bar stays always undefined

A little testing shows the core problem:
---
String.prototype.foo = function() {
  return typeof this;
}

alert("x".foo()); // alerts "string"
---

I.e., some optimization that prevents creating new objects, that
probably works well for built-in functions, is also applied to
user-added methods on String.prototype.
Same problem exists for Number and Boolean.

/L
--
Lasse Reichstein Nielsen
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google