JSFiddle - React, Tailwind, and code Playground

by joplomacedo

JavaScript

/*
this is bound to the global object, not the this variable of the outer function it's invoked from
*/

var my_object = {
    value: 0,
    increment: function(inc) {
        this.value += typeof inc === 'number' ? inc : 1;
    }
};


var sum = {
    value: 9,
    what: my_object.increment(9)
};

alert(my_object.value);