JSFiddle - React, Tailwind, and code Playground
by KendoDev
JavaScript
var x= 5,
o = {};
function f(x, o) {
with (o)
alert(x); // looks for x from o which mentioned in WITH statement
}
f(x,o); // if it doesn't find x inside o then reads x from function argument - confusion 1
o.x = "Hello";
f(x,o); // reads x from o
function f1(x, o) {
with (o)
x = "Hello1";
y = "Hi";
}
f1(x,o);
alert( o.x + '\n' + o.y); // inside WITH y is NOT created inside o as we expect, it creates just globally - confusion 2
alert(y); // globally created inside with
// instead of with
// just use like
var obj = {prop: {a:1} };
var temp = obj.prop;
temp.a = 2;
temp.b = 3;