Question

In js I'd do:

delete myobj.prototype["mything"]

How is this accomplished with clojurescript?

Was it helpful?

Solution

Just use built-in google closure wrapper around delete:

(goog.object.remove (.-prototype myobj) "mything")

OTHER TIPS

I have never try it in production mode but this problem seems to be fixed according to this other os question ClojureScript: How to add method via prototype to JS Object?

And this is my proposal to fix your problem:

Adding prototype property

(set! (.-foo (.-prototype js/String)) (fn [] "bar"))
(.-foo "test")
=>#<function (){return "bar";}>

Nulling this property

(set! (.-foo (.-prototype js/String)) nil)
(.-foo "test")
=> nil
(undefined? (.-foo "test"))
=> false

And following the "undefined" mozilla description specification .

undefined is a property of the global object, i.e. it is a variable in global scope. The initial value of undefined is the primitive value undefined.

Then I'll try with js/undefined

(set! (.-foo (.-prototype js/String)) js/undefined)
(.-foo "test")
=> nil
(undefined? (.-foo "test"))
=> true

good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top