TheDeveloperBlog.com

Home | Contact Us

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

JavaScript Reflect apply() Method

JavaScript Reflect apply() Method with examples on javascript reflect methods, apply() construct(), defineProperty() method, deleteProperty(), get(), getOwnPropertyDescriptor(), getPrototypeOf(), has(), isExtensible(), ownKeys(), setPrototypeOf() etc.

<< Back to JAVASCRIPT

JavaScript Reflect.apply() Method

The static Reflect.apply() method of JavaScript is used to call a function using the specified argument.

Syntax

Reflect.apply(target, thisArgument, argumentsList)

Parameter

target: It is the target function to call.

thisArgument: It is the value of this provided for the call to target.

ArgumentsList: It is an array-like object specifying the argument with which target should be called.

Return

The result of calling the given target function with the specified this value and arguments.

Exceptions

This method will throw a TypeError if the target is not callable.

Example 1

function g (a, b) {
    this.x = a;
    this.y = b;
}const obj = {};
Reflect.apply ( g , obj, [33,44] );
console.log( obj );

Output:

Object { x: 33, y: 44 }

Example 2

var whatsThis = function() { console.log(this); }
Reflect.apply(whatsThis, 'hello', []);

// Call a function that takes a variable number of args
var numbers = [3, 20, 1, 55];
console.log(Reflect.apply(Math.max, undefined, numbers));

Output:

"hello"
   55

Example 3

console.log(Reflect.apply(Math.floor, undefined, [45]));
console.log(Reflect.apply(String.fromCharCode, undefined, [104, 101,103,105]));
console.log(Reflect.apply(RegExp.prototype.exec, /ab/, ['confabulation']).index);
console.log(Reflect.apply(''.charAt, 'Rahul', [3]));

Output:

    45
   "hegi"
    4
   "u"

Next TopicJavaScript Reflect




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