C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.setPrototypeOf() MethodThe handler.setPrototypeOf method returns a Boolean value true if [[Prototype]] was successfully changed. Otherwise, it will return false. It is a trap for Object.setPrototypeOf(). SyntaxsetPrototypeOf: function(target, prototype) Parameterstarget: The target object. prototype: The object's new prototype or null. Return valueReturn a Boolean type value. Browser Support
Example 1<script> var pro = { f:13} var proxy = new Proxy(pro, { setPrototypeOf(target, newProto) { return newPrototype in target; } }); document.writeln('f' in proxy); //expected output: true </script> Output: true Example 2<script> var soo={ foo:1 } var proxy = new Proxy(soo, { setPrototypeOf(target, newProto) { } }); document.writeln('a' in proxy); //expected output: false </script> Output: false Example 3<script> var xyz = new Proxy({}, { setPrototypeOf(target, newProto) { if(key == "a") return true; return ;false } } ) var first= ("f" in xyz) var last = ("g" in xyz) document.write(""+first) //expected output:false document.write(' Output: false false
Next TopicJavaScript handler
|