我知道document.createElement
和document.registerElement
,但这些方法不允许使用自定义参数编写构造函数我想要像 new Image()这样的东西对于img标签。我写了以下代码:
SVG = document.getElementById('sprite').content.children[0]
class DisplayObject
constructor: (childs)->
clone = document.importNode SVG
clone.__proto__ = {
constructor: DisplayObject
__proto__: SVG.__proto__
}
clone.constructor = DisplayObject
return clone
__proto__: SVG.__proto__
test: ->
console.log 'test method'
问题是我无法从返回的克隆对象访问测试方法。谢谢
答案 0 :(得分:0)
也许这就是你要找的东西:
SVG = document.getElementById('flybar').children[0]
class DisplayObject
constructor: (children)->
@__proto__ = SVG.__proto__
return
test: =>
console.log 'test method'