这个JS的coffeescript翻译出了什么问题?

时间:2016-03-20 08:55:11

标签: coffeescript

试图提高我的Coffeescript技能,所以我想我会隐瞒这个jcrop demo。然而,它没有按预期工作。具体来说,似乎没有调用redraw函数。

这很好用。

// Create a new Selection object extended from Selection
  var CircleSel = function(){ };

  // Set the custom selection's prototype object to be an instance
  // of the built-in Selection object
  CircleSel.prototype = new $.Jcrop.component.Selection();

  // Then we can continue extending it
  $.extend(CircleSel.prototype,{
    zoomscale: 1,
    attach: function(){
      this.frame.css({
        background: 'url(' + $('#target')[0].src.replace('750','750') + ')'
      });
    },
    positionBg: function(b){
      var midx = ( b.x + b.x2 ) / 2;
      var midy = ( b.y + b.y2 ) / 2;
      var ox = (-midx*this.zoomscale)+(b.w/2);
      var oy = (-midy*this.zoomscale)+(b.h/2);
      //this.frame.css({ backgroundPosition: ox+'px '+oy+'px' });
      this.frame.css({ backgroundPosition: -(b.x+1)+'px '+(-b.y-1)+'px' });
    },
    redraw: function(b){

      // Call original update() method first, with arguments
      $.Jcrop.component.Selection.prototype.redraw.call(this,b);

      this.positionBg(this.last);
      return this;
    },
    prototype: $.Jcrop.component.Selection.prototype
  }); 

但是当我尝试在Coffescript中写这个时,它失败了

  CircleSel.prototype = new ($.Jcrop.component.Selection)

  $.extend CircleSel.prototype,
    zoomscale: 1
    attach: ->
      @frame.css background: 'url(' + $('#target')[0].src.replace('750', '750') + ')'
      return
    positionBg: (b) ->
      midx = (b.x + b.x2) / 2
      midy = (b.y + b.y2) / 2
      ox = -midx * @zoomscale + b.w / 2
      oy = -midy * @zoomscale + b.h / 2
      @frame.css backgroundPosition: -(b.x + 1) + 'px ' + -b.y - 1 + 'px'
      return
# this redraw function is not being called, everything else appears to work fine
    redraw: (b) ->
      $.Jcrop.component.Selection::redraw.call this, b
      @positionBg @last
      this
    prototype: $.Jcrop.component.Selection.prototype

我做错了什么?

0 个答案:

没有答案