Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to subclass PVector for example? #20

Open
soswow opened this issue Feb 21, 2014 · 2 comments
Open

Is there a way to subclass PVector for example? #20

soswow opened this issue Feb 21, 2014 · 2 comments

Comments

@soswow
Copy link

soswow commented Feb 21, 2014

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.

@fjenett
Copy link
Owner

fjenett commented Feb 28, 2014

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

@soswow
Copy link
Author

soswow commented Feb 28, 2014

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 =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants