本文介绍了coffeescript类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我用新的Kinetic.Stage替换新的画廊代码工作正常
当我使用dirived类不工作。
为什么是从Kinetic.Sine错误导出图库的种类?
width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0
height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0
类库扩展Kinetic.Stage
构造函数:(config) - >
super(config)
window.onload = - >
list_of_photos = jQuery('#_ image img')
x_pos = width / 4
y_pos = height / 4
stage = new Gallery
container:gallery_container
width:width
height:height
images_layer = new Kinetic.Layer()
在list_of_photos中的图片
imageObj = new Image )
imageObj.src = image.src
x_pos = x_pos + 100
y_pos = y_pos + 10
ori = new Kinetic.Image
x:x_pos
y :y_pos
image:imageObj
draggable:true
width:200
height:200
image_layer.add ori
stage.add images_layer
- 您必须使用其他方式调用super 类库扩展Kinetic.Stage
constructor:(config) - >
Kinetic.Stage.call(@,config)
示例:
UPD :我发现此问题仅存在于constructor方法中。确定为其他人:
类库扩展Kinetic.Stage
构造函数:(config)
Kinetic.Stage.call(@,config)
add:(item) - >
console.log(item)
super item
When I replace new Gallery with new Kinetic.Stage the code works properlyWhen I work with the dirived class it does not work.
Why is the kind of deriving Gallery from Kinetic.Stage wrong ?
width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0
height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0
class Gallery extends Kinetic.Stage
constructor: (config) ->
super(config)
window.onload = ->
list_of_photos = jQuery('#_image img')
x_pos = width/4
y_pos = height/4
stage = new Gallery
container: "gallery_container"
width: width
height: height
images_layer = new Kinetic.Layer()
for image in list_of_photos
imageObj = new Image()
imageObj.src = image.src
x_pos = x_pos + 100
y_pos = y_pos + 10
ori = new Kinetic.Image
x: x_pos
y: y_pos
image: imageObj
draggable: true
width: 200
height: 200
images_layer.add ori
stage.add images_layer
解决方案 Problem - Kineticjs Objects are not "compatible" with coffeescript classes.
Solving - You have to use other way of calling "super"
class Gallery extends Kinetic.Stage
constructor : (config) ->
Kinetic.Stage.call(@, config)
Example here : http://jsfiddle.net/lavrton/w2EQD/4/
UPD: I found that this problem exists only for "constructor" method. Ok for others:
class Gallery extends Kinetic.Stage
constructor: (config) ->
Kinetic.Stage.call(@, config)
add : (item) ->
console.log(item)
super item
这篇关于coffeescript类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!