The handler.deleteProperty function is utilized to completely eliminate a property by employing the delete operator. This function yields a true value if the deletion was accomplished successfully.
Syntax
Example
deleteProperty: function(target, property)
Parameters
Target : The target object.
Property : The name of the property to delete.
Return value
This procedure yields a Boolean result. It signifies whether the property has been successfully deleted or if the deletion has failed.
Browser Support
| Chrome | 49 |
|---|---|
Edge |
12 |
| Firefox | 18 |
| Opera | 36 |
Example 1
Example
var proxy = new Proxy({}, {
deleteProperty: function(target, prop) {
document.writeln("Called: " + prop);
return true;
//if sucessfullt delete,return true.
}
});delete proxy.abc;
Output:
Output
Called: abc
Example 2
Example
var proxy = new Proxy({}, {
deleteProperty: function(target, name) {
document.write('In delete Property ');
return delete target[name];
}
});
delete proxy.foo;
document.writeln(proxy.name);
Output:
Output
In delete Property undefined
Example 3
Example
var f = { bar: 'baz' }
f.bar = 'baz'
document.writeln('bar' in f)
delete f.bar
document.writeln('bar' in f)
var foo = { bar: 'baz' }
foo.bar = 'baz'
document.writeln('bar' in foo)
Output:
Output
true false true