Google Chrome "differences"

Discussion in 'Javascript' started by Gregor Kofler, Sep 3, 2008.

  1. 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 = function() {
    if (! { = [];
    // stays always undefined

    Trying a workaround I came across = []; = function() {{
    o: this,
    p: "baz"
    return this;

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

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

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

    Any comments on that?

    Gregor Kofler, Sep 3, 2008
    1. Advertisements

  2. .... and ...
    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.

    Lasse Reichstein Nielsen, Sep 4, 2008
    1. Advertisements

  3. A little testing shows the core problem:
    --- = 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.

    Lasse Reichstein Nielsen, Sep 4, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.