Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Scope, and using 'this' in the context of ionic components. Is it the same as using 'this' in a standard javascript environment?

$
0
0

@jaydz wrote:

Until recently, I was under the impression that using the 'this' keyword using ionic's product and its' Component/Page structure was not "bad". As an example, I have a page called TicketsPage. Im especially curious in two regards.
@Component ({
selector: 'page-tickets',
templateUrl: 'tickets-html',
}).

export class TicketsPage {
venues: any;
users: any;

constructor (public mySharedOb: MySharedOb) {

this.venues = [];
this.user = {};
this.user['tickets'] = [];
}

getTickets(){
for (var i = 0; i < this.user['tickets'].length; i++) {
this.venues.push( this.user['tickets'][i] )
}

}

My questions are:

  1. Simply put, is this a bad practice? Is using 'this' and assigning it properties the same as using 'this' in a not-ionic environment?

  2. Is my use of 'this' creating properties on and/or exposing the global environment?

  3. Or am I creating properties on TicketsPage, my ionic page?

  4. Being that TicketsPage is a 'class', is using 'this' in reference to it just fine?

  5. Is creating this.venues as an array in TicketsPage's constructor any better/worst/different than creating this.user as an object in TicketsPage's constructor and assigning this.user new properties?

Sorry to post a pretty basic Javascript question here, but from what I understood, using classes and using them in Ionic's context had different implications. Am I wrong?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles