Typescript transpiler (v 3.0.1) does not add functions to Object.protorype [on hold]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I'm trying out some beginner level typescript. As you notice in the typescript file, I have used arrow functions and plain vanilla javascript functions. The plain functions are added to the Object.prototype, but the arrow functions are added to the "this" object. Can someone help me figure out, why the differences?



// .ts file
interface IPerson
getFirstName(): string;
getLastName(): string;
setFirstName(firstName: string): void;
setLastName(lastName: string): void;


interface IStudent
getDepartment(): string;
setDepartment(dept: string): void;


class Person
private _firstName: string;
private _lastName: string;

constructor()
this._firstName = 'John';
this._lastName = 'Smith';

getFirstName = () =>
return this._firstName;

getLastName ()
return this._lastName;

setFirstName = (firstName: string): void =>
this._firstName = firstName;

setLastName(lastName: string): void
this._lastName = lastName;



class TA extends Person implements IPerson, IStudent
private _dept: string;

constructor()
super();
this._dept = 'NA';


getDepartment ()
return this._dept;

setDepartment (dept: string)
this._dept = dept;



let ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');

// transpiled js file
"use strict";
var __extends = (this && this.__extends) || (function ()
var extendStatics = function (d, b)
function (d, b) for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; ;
return extendStatics(d, b);

return function (d, b)
extendStatics(d, b);
function __() this.constructor = d;
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
;
)();
var Person = /** @class */ (function ()
function Person()
var _this = this;
this.getFirstName = function ()
return _this._firstName;
;
this.setFirstName = function (firstName)
_this._firstName = firstName;
;
this._firstName = 'John';
this._lastName = 'Smith';

Person.prototype.getLastName = function ()
return this._lastName;
;
Person.prototype.setLastName = function (lastName)
this._lastName = lastName;
;
return Person;
());
var TA = /** @class */ (function (_super)
__extends(TA, _super);
function TA()
var _this = _super.call(this)
TA.prototype.getDepartment = function ()
return this._dept;
;
TA.prototype.setDepartment = function (dept)
this._dept = dept;
;
return TA;
(Person));
var ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');






share|improve this question











put on hold as off-topic by Stephen Rauch, Malachi♦ Aug 3 at 15:11


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.












  • Code Review is not a site where we explain some one else's code, we expect that the code is yours and that you know what it is doing and why.
    – Malachi♦
    Aug 3 at 15:15










  • I wrote this piece of code to demonstrate the behavior of typescript code when written in two different ways. This is my code. The transpiled code is auto-generated by transpiler. My question is what is the best practice? Usage of arrow function or use the vanilla javascript code.
    – Amit
    2 days ago







  • 1




    Stackoverflow is probably the better place for this kind of question. A quick search on google yields what you are looking for in the very first answer.
    – Daniele Torino
    8 hours ago

















up vote
0
down vote

favorite












I'm trying out some beginner level typescript. As you notice in the typescript file, I have used arrow functions and plain vanilla javascript functions. The plain functions are added to the Object.prototype, but the arrow functions are added to the "this" object. Can someone help me figure out, why the differences?



// .ts file
interface IPerson
getFirstName(): string;
getLastName(): string;
setFirstName(firstName: string): void;
setLastName(lastName: string): void;


interface IStudent
getDepartment(): string;
setDepartment(dept: string): void;


class Person
private _firstName: string;
private _lastName: string;

constructor()
this._firstName = 'John';
this._lastName = 'Smith';

getFirstName = () =>
return this._firstName;

getLastName ()
return this._lastName;

setFirstName = (firstName: string): void =>
this._firstName = firstName;

setLastName(lastName: string): void
this._lastName = lastName;



class TA extends Person implements IPerson, IStudent
private _dept: string;

constructor()
super();
this._dept = 'NA';


getDepartment ()
return this._dept;

setDepartment (dept: string)
this._dept = dept;



let ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');

// transpiled js file
"use strict";
var __extends = (this && this.__extends) || (function ()
var extendStatics = function (d, b)
function (d, b) for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; ;
return extendStatics(d, b);

return function (d, b)
extendStatics(d, b);
function __() this.constructor = d;
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
;
)();
var Person = /** @class */ (function ()
function Person()
var _this = this;
this.getFirstName = function ()
return _this._firstName;
;
this.setFirstName = function (firstName)
_this._firstName = firstName;
;
this._firstName = 'John';
this._lastName = 'Smith';

Person.prototype.getLastName = function ()
return this._lastName;
;
Person.prototype.setLastName = function (lastName)
this._lastName = lastName;
;
return Person;
());
var TA = /** @class */ (function (_super)
__extends(TA, _super);
function TA()
var _this = _super.call(this)
TA.prototype.getDepartment = function ()
return this._dept;
;
TA.prototype.setDepartment = function (dept)
this._dept = dept;
;
return TA;
(Person));
var ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');






share|improve this question











put on hold as off-topic by Stephen Rauch, Malachi♦ Aug 3 at 15:11


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.












  • Code Review is not a site where we explain some one else's code, we expect that the code is yours and that you know what it is doing and why.
    – Malachi♦
    Aug 3 at 15:15










  • I wrote this piece of code to demonstrate the behavior of typescript code when written in two different ways. This is my code. The transpiled code is auto-generated by transpiler. My question is what is the best practice? Usage of arrow function or use the vanilla javascript code.
    – Amit
    2 days ago







  • 1




    Stackoverflow is probably the better place for this kind of question. A quick search on google yields what you are looking for in the very first answer.
    – Daniele Torino
    8 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying out some beginner level typescript. As you notice in the typescript file, I have used arrow functions and plain vanilla javascript functions. The plain functions are added to the Object.prototype, but the arrow functions are added to the "this" object. Can someone help me figure out, why the differences?



// .ts file
interface IPerson
getFirstName(): string;
getLastName(): string;
setFirstName(firstName: string): void;
setLastName(lastName: string): void;


interface IStudent
getDepartment(): string;
setDepartment(dept: string): void;


class Person
private _firstName: string;
private _lastName: string;

constructor()
this._firstName = 'John';
this._lastName = 'Smith';

getFirstName = () =>
return this._firstName;

getLastName ()
return this._lastName;

setFirstName = (firstName: string): void =>
this._firstName = firstName;

setLastName(lastName: string): void
this._lastName = lastName;



class TA extends Person implements IPerson, IStudent
private _dept: string;

constructor()
super();
this._dept = 'NA';


getDepartment ()
return this._dept;

setDepartment (dept: string)
this._dept = dept;



let ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');

// transpiled js file
"use strict";
var __extends = (this && this.__extends) || (function ()
var extendStatics = function (d, b)
function (d, b) for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; ;
return extendStatics(d, b);

return function (d, b)
extendStatics(d, b);
function __() this.constructor = d;
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
;
)();
var Person = /** @class */ (function ()
function Person()
var _this = this;
this.getFirstName = function ()
return _this._firstName;
;
this.setFirstName = function (firstName)
_this._firstName = firstName;
;
this._firstName = 'John';
this._lastName = 'Smith';

Person.prototype.getLastName = function ()
return this._lastName;
;
Person.prototype.setLastName = function (lastName)
this._lastName = lastName;
;
return Person;
());
var TA = /** @class */ (function (_super)
__extends(TA, _super);
function TA()
var _this = _super.call(this)
TA.prototype.getDepartment = function ()
return this._dept;
;
TA.prototype.setDepartment = function (dept)
this._dept = dept;
;
return TA;
(Person));
var ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');






share|improve this question











I'm trying out some beginner level typescript. As you notice in the typescript file, I have used arrow functions and plain vanilla javascript functions. The plain functions are added to the Object.prototype, but the arrow functions are added to the "this" object. Can someone help me figure out, why the differences?



// .ts file
interface IPerson
getFirstName(): string;
getLastName(): string;
setFirstName(firstName: string): void;
setLastName(lastName: string): void;


interface IStudent
getDepartment(): string;
setDepartment(dept: string): void;


class Person
private _firstName: string;
private _lastName: string;

constructor()
this._firstName = 'John';
this._lastName = 'Smith';

getFirstName = () =>
return this._firstName;

getLastName ()
return this._lastName;

setFirstName = (firstName: string): void =>
this._firstName = firstName;

setLastName(lastName: string): void
this._lastName = lastName;



class TA extends Person implements IPerson, IStudent
private _dept: string;

constructor()
super();
this._dept = 'NA';


getDepartment ()
return this._dept;

setDepartment (dept: string)
this._dept = dept;



let ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');

// transpiled js file
"use strict";
var __extends = (this && this.__extends) || (function ()
var extendStatics = function (d, b)
function (d, b) for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; ;
return extendStatics(d, b);

return function (d, b)
extendStatics(d, b);
function __() this.constructor = d;
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
;
)();
var Person = /** @class */ (function ()
function Person()
var _this = this;
this.getFirstName = function ()
return _this._firstName;
;
this.setFirstName = function (firstName)
_this._firstName = firstName;
;
this._firstName = 'John';
this._lastName = 'Smith';

Person.prototype.getLastName = function ()
return this._lastName;
;
Person.prototype.setLastName = function (lastName)
this._lastName = lastName;
;
return Person;
());
var TA = /** @class */ (function (_super)
__extends(TA, _super);
function TA()
var _this = _super.call(this)
TA.prototype.getDepartment = function ()
return this._dept;
;
TA.prototype.setDepartment = function (dept)
this._dept = dept;
;
return TA;
(Person));
var ta1 = new TA();
ta1.setFirstName('F1');
ta1.setLastName('L1');
ta1.setDepartment('D1');








share|improve this question










share|improve this question




share|improve this question









asked Aug 3 at 8:46









Amit

385




385




put on hold as off-topic by Stephen Rauch, Malachi♦ Aug 3 at 15:11


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Stephen Rauch, Malachi♦ Aug 3 at 15:11


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.











  • Code Review is not a site where we explain some one else's code, we expect that the code is yours and that you know what it is doing and why.
    – Malachi♦
    Aug 3 at 15:15










  • I wrote this piece of code to demonstrate the behavior of typescript code when written in two different ways. This is my code. The transpiled code is auto-generated by transpiler. My question is what is the best practice? Usage of arrow function or use the vanilla javascript code.
    – Amit
    2 days ago







  • 1




    Stackoverflow is probably the better place for this kind of question. A quick search on google yields what you are looking for in the very first answer.
    – Daniele Torino
    8 hours ago

















  • Code Review is not a site where we explain some one else's code, we expect that the code is yours and that you know what it is doing and why.
    – Malachi♦
    Aug 3 at 15:15










  • I wrote this piece of code to demonstrate the behavior of typescript code when written in two different ways. This is my code. The transpiled code is auto-generated by transpiler. My question is what is the best practice? Usage of arrow function or use the vanilla javascript code.
    – Amit
    2 days ago







  • 1




    Stackoverflow is probably the better place for this kind of question. A quick search on google yields what you are looking for in the very first answer.
    – Daniele Torino
    8 hours ago
















Code Review is not a site where we explain some one else's code, we expect that the code is yours and that you know what it is doing and why.
– Malachi♦
Aug 3 at 15:15




Code Review is not a site where we explain some one else's code, we expect that the code is yours and that you know what it is doing and why.
– Malachi♦
Aug 3 at 15:15












I wrote this piece of code to demonstrate the behavior of typescript code when written in two different ways. This is my code. The transpiled code is auto-generated by transpiler. My question is what is the best practice? Usage of arrow function or use the vanilla javascript code.
– Amit
2 days ago





I wrote this piece of code to demonstrate the behavior of typescript code when written in two different ways. This is my code. The transpiled code is auto-generated by transpiler. My question is what is the best practice? Usage of arrow function or use the vanilla javascript code.
– Amit
2 days ago





1




1




Stackoverflow is probably the better place for this kind of question. A quick search on google yields what you are looking for in the very first answer.
– Daniele Torino
8 hours ago





Stackoverflow is probably the better place for this kind of question. A quick search on google yields what you are looking for in the very first answer.
– Daniele Torino
8 hours ago
















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Python Lists

Aion

JavaScript Array Iteration Methods