What’s the purpose of prototype? [duplicate]

This question already has answers here: Use of ‘prototype’ vs. ‘this’ in JavaScript? (15 answers) Closed 1 year ago. Possible Duplicate: Use of ‘prototype’ vs. ‘this’ in JavaScript? OK, So I am somewhat new to the idea of OOP in JS. What is the difference between these two snippets of code written below: function animal(){ … Read more

Benefits of prototypal inheritance over classical?

So I finally stopped dragging my feet all these years and decided to learn JavaScript “properly”. One of the most head-scratching elements of the languages design is its implementation of inheritance. Having experience in Ruby, I was really happy to see closures and dynamic typing; but for the life of me can’t figure out what … Read more

Better way to sum a property value in an array

I have something like this: $scope.traveler = [ { description: ‘Senior’, Amount: 50}, { description: ‘Senior’, Amount: 50}, { description: ‘Adult’, Amount: 75}, { description: ‘Child’, Amount: 35}, { description: ‘Infant’, Amount: 25 }, ]; Now to have a total Amount of this array I’m doing something like this: $scope.totalAmount = function(){ var total = … Read more