I\'m having trouble understanding why, in strict mode, a syntax error occurs when delete is used on an unqualified identifier.
In most cases, it makes s
If you want to delete object in strict mode. You have to explicitly mention about the property access. Also note that, how you call the function is important. If new operator isn't used this is undefined under use strict, and you cant use the below method.
Example:
'use strict'
function func(){
var self = this;
self.obj = {};
self.obj.x = 'y'
console.log(self.obj);
delete self.obj // works
// delete obj // doesn't work
console.log(self.obj);
}
var f = new func();
For deleting object outside of the function(closure), you will have to call like
// same code as above delete f.obj