Protocols – Extend the protocol in CLOJUREScript to get values ​​from this machine JS object

I have a code base that uses a lot of get and get-in for nested forms. I want to be able to use native javascript objects without (a lot of) code rewriting.

js> cljs.user.o = {foo: 42} // in js console

cljs.user> (get o "foo" ); => 42; in cljs console

Since I only query the forms, but do not modify them, I think it is enough to implement get (get-in dependency). This is my attempt,

(extend-protocol ILookup
js/Object
(-lookup [mk] (aget mk))
(-lookup [mk not-found (or (aget mk) not-found)))

It seems to work, but it breaks a lot of things in a strange way.

You are modifying the Object prototype, you don’t want to do this, the following is better:

 (extend-protocol ILookup
object
(-lookup [mk] (aget mk))
(-lookup [mk not-found] (or (aget mk) not-found)))

I have a code base that uses a lot of get and get-in for nested forms. I want to be able to use native javascript objects without (a lot of) code rewriting .

js> cljs.user.o = {foo: 42} // in js console

cljs.user> (get o "foo"); => 42; in cljs console

Since I only query the forms, but don’t modify them, I think it is enough to implement get (get-in dependency). This is my attempt ,

< p>

(extend-protocol ILookup
js/Object
(-lookup [mk] (aget mk))
(-lookup [mk not-found (or (aget mk) not-found)))

It seems to work, but it breaks a lot of things in a strange way.

< p>You are modifying the Object prototype and you don’t want to do this. The following is better:

(extend-protocol ILookup
object
(-lookup [mk] (aget mk))
(-lookup [mk not-found] (or (aget mk) not-found)))

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2486 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.