MELWIN VINCENT
MELWIN VINCENT

Reputation: 1

Any performance improvement when passing variables than the whole object from HTML to Javascript in AngularJS

I can either pass the iterating object as a whole from HTML to Javascript as shown below

<!-- HTML --!>
(click)="onChange(item)"
/* js */
onChange(item) {
getDetails(item.id, item.date, item.count)
}

or I can pass the only required properties of the iterating object as shown below

<!-- HTML --!>
(click)="onChange(item.id, item,date, item.count)"
/* js */
onChange(id, date, count) {
this.getDetails(id, date, count)
}

Consider the iterating item is having around 15 properties

item = {
id:"01",
date: "12/12/2017",
count:"1000",
name:"John Doe",
email:"[email protected]"
...
...
... // goes on 

}

I just want to know which of the above approach gives better performance, passing the properties or the whole object ? I believe , I just want to pass the properties only. Anyway the code is running faster in both ways. But if some could explain the real difference, it would be great.

Upvotes: 0

Views: 37

Answers (1)

BunnyDhaliwal
BunnyDhaliwal

Reputation: 100

I think javascript engines like v8 store their object properties in hash map which makes it o(1), therefore if you pass the object and access the properties from inside the function it would not make any difference, however if you iterate over it, it would be slower

Upvotes: 1

Related Questions