0

I want to create an JavaScript Image object and set the src property. I tried:

(set! (.-src (js/Image. 80 80)) "foo.png")

But the return value of this will be "foo.png".

How do I set the src property and return the #<[object HTMLImageElement]>?

Ultimately I want to create a sequence of images with the sources "1.png", "2.png"... so was hoping the following would work:

(map (fn [x] (aset (js/Image. 80 80) "src" (str x ".png"))) (range 0 11))
1
  • Be advised, though, that map is lazy, so you might not get what you expect. You may want to go with doseq, instead. Commented May 13, 2014 at 7:15

1 Answer 1

3
(let [the-image (js/Image. 80 80)]
   (set! (.-src the-image) "foo.png")
   the-image ;;=> the full image is here with the src = foo.png
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.