簡體   English   中英

coffeescript類

[英]coffeescript Class

當我用新的Kinetic.Stage替換新的Gallery時,代碼正常工作當我使用派生的類時,它不起作用。

為什么從Kinetic.Stage派生Gallery是錯誤的?

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

問題 -Kineticjs對象與coffeescript類不“兼容”。

解決 -您必須使用其他方式來稱呼“超級”

class Gallery extends Kinetic.Stage
    constructor : (config) ->
        Kinetic.Stage.call(@, config)

此處的示例: http : //jsfiddle.net/lavrton/w2EQD/4/

UPD :我發現此問題僅存在於“構造函數”方法中。 還可以:

class Gallery extends Kinetic.Stage
  constructor: (config) -> 
    Kinetic.Stage.call(@, config)
  add : (item) ->
    console.log(item)
    super item

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM