coffeescript-mode-processing icon indicating copy to clipboard operation
coffeescript-mode-processing copied to clipboard

Is there a way to subclass PVector for example?

Open soswow opened this issue 11 years ago • 2 comments

Point = (function (_super) {
            __extends(Point, _super);
            Point.name = 'Point';
            function Point() {
                return Point.__super__.constructor.apply(this, arguments);
            }
            return Point;
        }) (PVector);

I try to subclass PVector. Resulting class is not what expected, constructor doesn't call PVector's constructor. Looks like Point.super.constructor is general Object constructor, not PVector's one.

I don't know why ProcessingJS has these lines in PVector.js. I think this is A problem.

soswow avatar Feb 21 '14 17:02 soswow

I have never tried ... can you give a longer example of what you are trying to do?

fjenett avatar Feb 28 '14 10:02 fjenett

TestingCoffeeMode.pde:

class Point
  x: null
  y: null
  constructor: (@x, @y) ->

p1: null

setup: ->
  size 500, 500
  @p1 = new Point(20, 30)

draw: ->
  background 255
  stroke 0
  line @p1.x,@p1.y,100,100

It works ok!

But If I want to use mighty PVector as by extends:

p1: null
setup: ->
  class @Point extends PVector
  size 500, 500
  @p1 = new @Point(20, 30)

draw: ->
  background 255
  stroke 0
  line @p1.x,@p1.y,100,100

It stops working.

The problem is that in the line

function Point() {
  return Point.__super__.constructor.apply(this, arguments);
}

Doesn't point to PVector.constructor as it should, but points to Object. Point.__super__.constructor == Object gives true =)

soswow avatar Feb 28 '14 14:02 soswow