Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in ClojureScript by

my function has to take a document element and invoke element.webkitRequestFullscreen()
or element .mozRequestFullscreen () .. depending on the browser.

(defn somfn[elem]
..

(exists? elem.requestFullscreen)

..

does not compile. I get this message js/elem is shadowed by a local

How do I fix this ?

2 Answers

+1 vote
ago by
selected ago by
 
Best answer

You can just check the property via regular access in cases where it returns a true-ish value if it exists

(if elem.requestFullScreen ...)

or the slightly more correct version

(if (.-requestFullScreen elem) ...)

These doesn't work for cases where the property may exist but may be nil or false though.

+2 votes
ago by

You can use goog.object API

`
(ns my.app
(:require [goog.object :as gobj]))
(defn somefn
[elem]
(if (gobj/containsKey elem "requestFullscreen")

...))

`

https://google.github.io/closure-library/api/goog.object.html

ago by
Yeah, in javascript you can use the in operator: `if ("requestFullscreen" in elem)` , but it's not supported in cljs.

goog.object/containsKey  is just a wrappor for the `in` opeartor.


goog.object.containsKey = function(obj, key) {
  return obj !== null && key in obj;
};
...