how do you do this: ```delete obj['property']```
# javascript
b
how do you do this:
Copy code
delete obj['property']
1
r
Copy code
external fun delete(p: dynamic)
a
Only with the embedded js syntax:
Copy code
js("delete obj['property']")
Could you please describe your use-case? It's possible that your use-case could be solved in a different way, or it's so essential that we should give an access to our internal function called
jsDeleteProperty
b
use case is mutating a js object in a callback from an external API; the first place that I've checked was the MutableRecord interface and I think inlining JS should work fine there
hm, is this not supported when inlining js
Copy code
fun Any.deleteProperty(property: String) = js("delete this[property]")
does not work, this works:
Copy code
fun deleteProperty(obj: Any, property: String) = js("delete obj[property]")
a
Yep, it's because it's trying to translate
this
as the JavaScript
this
. It's a problem we know about
❤️ 1
e
Btw @Bernhard, kotlin-wrappers
js
module already provide this function if you're importing it for other needs.
b
thank you, I will take a look 🙂
✔️ 1
t
There is no needs in custom external
delete
It already exists in
Reflect
b
thank you Victor!