coffeescript-mode-processing
coffeescript-mode-processing copied to clipboard
Is there a way to subclass PVector for example?
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.
I have never tried ... can you give a longer example of what you are trying to do?
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 =)