JSFiddle - React, Tailwind, and code Playground

by lifecube

HTML

<button id="btn">trigger setNewName</button>
<div id="console"></div>

JavaScript

function log(msg) {
       $('#console').append($('<p/>').html(msg));
   }
   var MyApp = {};
   (function ($, a) {
       a.User = new function () {
           this.firstName = 'default first name';
           this.lastName = 'default last name';
           this.init = function (firstName, lastName) {
               this.firstName = firstName;
               this.lastName = lastName;
           };
           this.setNewName = function (firstName, lastName) {
               log('before first name is: ' + this.firstName); //work
               this.firstName = firstName;
               log('now the first name is: ' + this.firstName);
               //log(User.$editProfilePopups); //wont work
               //...
           };
       };
   })(jQuery, MyApp);

   jQuery(document).ready(function () {
       MyApp.User.init('Peter', 'T');
       $('#btn').click(function () {
           MyApp.User.setNewName('NewName1', 'NewName2');
       });
   });