ClojureScript

Property and method access on js/window

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

I noticed the following behaviour:

(.encodeURIComponent js/window "some text")

will fail under advanced compilation because the method name is optimised
This applies to any property or method of js/window.
The same does not appear to be true of js/document.

workaround as follows:

(def encode (aget js/window "encodeURIComponent"))
(encode "some txt")

Activity

Hide
David Nolen added a comment -

Is this still a problem?

Show
David Nolen added a comment - Is this still a problem?
Hide
Jozef Wagner added a comment -

This is not a bug. You should use

(js/encodeURIComponent s)

By standard, encodeURIComponent is a global object, not property of a window object. If you use such nonstandard call instead, google closure compiler will in advanced mode mangle its name, because it won't find it in default externs.

See default google closure externs, (see es3 for encodeURIComponent)

For nonstandard objects and those defined outside your clojurescript program, you should use

:externs ["src/externs.js"]
option when building.

Add you names into src/externs.js and you should be fine, e.g.:

window.prototype.encodeURIComponent = function() {};
Show
Jozef Wagner added a comment - This is not a bug. You should use
(js/encodeURIComponent s)
By standard, encodeURIComponent is a global object, not property of a window object. If you use such nonstandard call instead, google closure compiler will in advanced mode mangle its name, because it won't find it in default externs. See default google closure externs, (see es3 for encodeURIComponent) For nonstandard objects and those defined outside your clojurescript program, you should use
:externs ["src/externs.js"]
option when building. Add you names into src/externs.js and you should be fine, e.g.:
window.prototype.encodeURIComponent = function() {};
Hide
Dave Sann added a comment -

In chrome it seems to be both.

However, your point is valid.

I also use

window.x = function(){};

in externs. Which also seems to work.

Show
Dave Sann added a comment - In chrome it seems to be both. However, your point is valid. I also use window.x = function(){}; in externs. Which also seems to work.
Hide
David Nolen added a comment -

Not a bug.

Show
David Nolen added a comment - Not a bug.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: