C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.has() MethodThe handler.has() method used to "hide" any property you want. It's a trap for an operator. It returns the Boolean value true if you want the property to be accessed, otherwise false If the key is present or not in the original object. Syntax
has: function(target, prop) Parameters
target: The target object. prop: The property to check for existence. Return value
Return a Boolean value. Browser Support
Example 1
const x = { f:10 };
const proxy = new Proxy(x, {
has: function(target, name) {
document.writeln('in has');
//expected output: in has
return name in target;
}
});
document.writeln('f' in proxy);
//expected output: true
Output: in has true Example 2
var x={hoo:1}
var xyz = new Proxy(x, {
has: function(target, key) {
if(key == "a") return false;
return true;
}
}
)
var x= ("a" in xyz)
var y = ("b" in xyz)
document.write("a in d: " +x)
//expected output: a in d: false
document.write('Output: a in d: false b in d: true Example 3
var s={
voo:1
}
var p = new Proxy(s, {
has: function(target, prop) {
document.writeln('called: ' + prop);
return false;
}
});
document.writeln('a' in p);
//expected output:called: a false
Output: called: a false
Next TopicJavaScript handler
|