Are Typescript class objects slower in performance by wrapping together their methods?

Viewed 1701

I could be mistaken but by looking at typescripts playground I noticed that they wrap their classe's methods together with the object variable which feels like it may reduce performance every time I call a new object.

e.g. Typescript Playground Output of Class

var FatObject = (function () {
   function FatObject(thing) {
       this.objectProperty = 'string';
       this.anotherProp = thing;
   }
   FatObject.prototype.someMassivMethod = function () {
       //many lines of code 
       //...
       //...
       //...
       //.......................
    };
   return FatObject;
}());

var thing = 'example';
var objOne = new FatObject(thing);
var objTwo = new FatObject(thing);
var objThree = new FatObject(thing);
var objFour = new FatObject(thing);

I feel that if I write massive methods, each time I create a new object from the class I will also be compiling these massive methods.

Rather than declaring the methods outside the function name when I create new objects.

e.g. old way:

function ThinObj(thing) {
    this.anotherProp = thing;
    this.objectProperty = 'string';
}

ThinObj.prototype.someMassivMethod = function() {
    //many lines of code 
    //...
    //...
    //...
    //..................
}

const thing = 'example'
let objOne = new ThinObj(thing);
let objTwo = new ThinObj(thing);
let objThree = new ThinObj(thing);
let objFour = new ThinObj(thing);

Can anyone clarify if:

A: I am loading 4 types of functions in memory in the typescript example (or overwriting them since prototype is used - I'm still shakey with my understanding of prototype).

B: If more compiler work is happening with Typescript wrapping the methods together?

Thanks

1 Answers
Related