Am Fr., 28. Dez. 2018 um 01:48 Uhr schrieb Philos Kim <philo...@gmail.com>:

> The third party JS library I use requires implementing the static getter
> method of ES6.
>

AFAIK ClojureScript doesn't have a construct to generate getters / setters.
You can implement those via Object.defineProperty
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty>,
though.

Could anyone tell me how I can implement the following simple code in
> ClojureScript?
>
>
> class Person{
>   constructor(){
>     this._name = 'jack';
>   };
>
>   static get name(){
>     return this._name;
>   }
>
>   static set name(val){
>     this._name = val;
>   }
> }
>

(def Person
  (let [constructor (fn [] (this-as t (set! (.-_name t) "jack")))
        proto (doto #js{}
                (js/Object.defineProperty "name"
                  #js{:get #(this-as t (.-_name t))
                      :set #(this-as t (set! (.-_name t) %))}))]
    (set! (.-prototype constructor) proto)
    constructor))

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

Reply via email to