Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by wilson

Hi!

I need some way to store sth on class level and not per instance. I found this in the documentation:
http://impactjs.com/documentation/class-reference/class#staticinstantiate-function

But using MyEntity.someVar from an instance of MyEntity does not really work. What am I doing wrong or is it just not possible?

Thanks!

1 decade ago by quidmonkey

MyEntity.prototype.someVar

1 decade ago by dominic

How exactly are you trying to access the var? You can't access it with this.someVar, but have to use MyEntity.someVar. E.g.:

MyEntity = ig.Entity.extend({
	doSomething: function() {
		console.log( MyEntity.someVar ); // 42
	}
});

MyEntity.someVar = 42;

Edit: MyEntity.prototype.someVar, as quidmonkey suggested, will access the default value of an instance variable, without instantiating the entity. E.g.:

MyEntity = ig.Entity.extend({
	someVar: 42, // instance var with default 42
	doSomething: function() {
		console.log( this.someVar );
	}
});

console.log( MyEntity.prototype.someVar ); // 42

1 decade ago by wilson

Hey guys,

thanks for your quick responses! I just noticed them now...

@dominic I almost did it right, but tried to access MyEntity within its own definition context, what couldn't work obviously... Thanks!
Page 1 of 1
« first « previous next › last »