Javascript 扩展 NPObject(Google 地球插件 API)
我正在尝试在 Google 中扩展 KmlPlacemark
地球API。谷歌使用工厂方法来创建对象,所以我不能做这样的事情:
KmlPlacemark.prototype.foo = function () { /* ... */ }
我试图在创建每个对象后简单地向它们添加方法,
function foo () { /* ... */ }
placemarkObj.foo = foo;
但它抛出了
Error: Trying to add unsupported property on NPObject!
我最终只是为其制作了一个包装器,但我会还是想知道是否还有其他方法可以做到。
I'm trying to extend KmlPlacemark
in the Google Earth API. Google uses factory methods to create the objects so I can't do something like this:
KmlPlacemark.prototype.foo = function () { /* ... */ }
I tried to simply add methods to each of the objects after they were created
function foo () { /* ... */ }
placemarkObj.foo = foo;
but it throws
Error: Trying to add unsupported property on NPObject!
I ended up just making a wrapper for it, but I'd still want to know if there's any other way of doing it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定,但看起来您正在尝试扩展浏览器插件中存在的对象,这是不可能的 - 尽管可以在 JavaScript 中访问这些对象,但它们的实现是在 NPAPI 插件内的本机代码中。
I'm not absolutely sure, but it looks like you're trying to extend objects that exist inside the browser plugin, which isn't possible - although these objects can be accessed in JavaScript, their implementation is in native code inside the NPAPI plugin.