Вопрос

In js I'd do:

delete myobj.prototype["mything"]

How is this accomplished with clojurescript?

Это было полезно?

Решение

Just use built-in google closure wrapper around delete:

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

Другие советы

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!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top