자바스크립트

자바스크립트-멤버함수내에서 this를 항상 사용해야하는가?(생략가능한가?)

안녕1999 2017. 6. 7. 23:30
function test_gloval_function_x()
{
	console.log("test_gloval_function_x()");
}
var data1="global data1";
function test_meber_function_this()
{
	var o={};
	o.data1="meber data1";
	console.log("멤버함수내에서 this를 항상 사용해야하는가?(생략가능한가?)");

	o.test_gloval_function_x=function()
	{
		console.log("meber_function_x()");
	}
	o.test=function()
	{
		test_gloval_function_x();//test_gloval_function_x()
		console.log(data1);//global data1

		this.test_gloval_function_x();//meber_function_x
		console.log(this.data1);//meber data1
	}
	return o;
}
var a=test_meber_function_this();
a.test();

결론 : 사용해야함