The code below would invoke a function which adds the clicked name into an array. However, $(this) is calling the app object instead of the clicked text. I'm guessing I can't use $(this) and this in the same function and expect the this to be calling different things. Is there an alternative solution to this?
var App = function () {
this.friends = [];
};
App.prototype.addFriend = function () {
name = $(this).text();
this.friends.push(name);
}
var app = new App();
$(document).ready(function () {
$(document).on("click", ".user", function () {app.addFriend()});
}