How to get Type from an instance of that type

entity type Car mixes MyStats {
}

entity type Boat mixes MyStats {
}

type MyStats {
	fetchCountSquare: member function(): int js server
}


function fetchCountSquare() {
  return this.typeOf().typeRef.toType().fetchCount() ** 2 // <---how to get Type from an instance???
}

Car.fetch().objs.first().fetchCountSquare() --> 100 //because there are 10 cars
Boat.fetch().objs.first().fetchCountSquare() --> 121 //because there are 11 boats

Though not listed as a function in the c3ShowType, it seems that you can call a member function called type(), which returns the Type of your instance as found in this community post: How to call a static function from an instance or from a member function, in JS console.

In your case, you’d want to change your fetchCountSquare() function to be:

function fetchCountSquare() {
var count = this.type().fetchCount();
return Math.pow(count, 2);
}