TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript handler setPrototypeOf() Method

JavaScript handler setPrototypeOf() Method with examples on javascript handler, javascript methods, javascript tutorial, apply(), construct(), defineProperty(), deleteProperty(), get(), setPrototypeOf(), set(), ownKeys(), isExtensible() etc.

<< Back to JAVASCRIPT

JavaScript handler.setPrototypeOf() Method

The 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().

Syntax

setPrototypeOf: function(target, prototype)

Parameters

target: The target object.

prototype: The object's new prototype or null.

Return value

Return a Boolean type value.

Browser Support

Chrome Compatibility unknown
Edge Compatibility unknown
Firefox 49
Opera Compatibility unknown

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>
Test it Now

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>
Test it Now

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('
'); document.write("" +last) //expected output: false </script>
Test it Now

Output:

false
false

Next TopicJavaScript handler




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf