JSFiddle - React, Tailwind, and code Playground
by techunter
JavaScript
var title="'This' is global";
var popup={
dom_element:("#popup"),
title :"Color Picker",
prev_color :'#fff',
set_color : function(color){
color=color || this.prev_color;
//set the color
return color;
},
show :function(){
console.log(this); //the popup object
return "test";
}
};
var show=popup.show();
function test(){
console.log("test funcion called");
}
//Case 1: var show=popup.show()
console.log(show); //output "Color Picker"
//Case 2: var show=popup.show()
console.log(popup.show); //output "Color Picker"
//Case 3: var show=popup.show !!! (no parent.)
console.log(show()); //output "This is global"
console.log(window[popup.show()]());