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. Syntaxhas: function(target, prop) Parameterstarget: The target object. prop: The property to check for existence. Return valueReturn a Boolean value. Browser Support
Example 1const 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 2var 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 3var 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
|