veldise / js-examples

Javascript/NodeJS/AnlaurJS/Etc Code Examples
MIT License
0 stars 1 forks source link

Delete:"use strict"사용하면 지울 수 없다고 하는데, #2

Open JoonseokRyu opened 10 years ago

JoonseokRyu commented 10 years ago

"use strict"할 때, 지우는 것을 허용하지 않는다면, delete는 사용하지 않는건가요? 많은 문제가 있어서 그랬을 것같은데 왜 그럴까요?

Deleting a variable, a function, or an argument, is not allowed.

var testStrict = 3.14;
delete testStrict; // This causes an error. 
veldise commented 10 years ago

제가 알기로 delete 키워드는 object의 property를 삭제하는 키워드입니다.

var obj = {
    a: 123,
    b: 'hello'
};
console.log(obj); // { a: 123, b: 'hello' }
delete obj.a;
console.log(obj); // { b: 'hello' }

이슈에 해당하는 코드는 로컬 변수를 삭제하는 건데, 이게 맞는 코드인지 잘 모르겠군요.

strict mode를 사용하지 않아도 로컬 변수가 남아있는 걸 볼 때 이슈의 코드는 맞지 않는 코드라고 생각됩니다.

var text = 'hello';
console.log(text); // hello
delete text;
console.log(text); // hello
veldise commented 10 years ago

http://msdn.microsoft.com/ko-kr/library/2b2z052x(v=vs.94).aspx