{"id":1177,"date":"2023-05-21T07:01:08","date_gmt":"2023-05-21T07:01:08","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=1177"},"modified":"2023-05-21T07:01:39","modified_gmt":"2023-05-21T07:01:39","slug":"what-is-the-difference-between-call-and-apply","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/21\/what-is-the-difference-between-call-and-apply\/","title":{"rendered":"What is the difference between .call() and .apply()?"},"content":{"rendered":"\n<p>The function .call() and .apply() are very similar in their usage except a little difference. .call() is used when the number of the function\u2019s arguments are known to the programmer, as they have to be mentioned as arguments in the call statement. On the other hand, .apply() is used when the number is not known. The function .apply() expects the argument to be an array.<\/p>\n\n\n\n<p>The basic difference between .call() and .apply() is in the way arguments are passed to the function. Their usage can be illustrated by the given example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var someObject = {\nmyProperty : 'Foo',\n\nmyMethod : function(prefix, postfix) {\n\n    alert(prefix + this.myProperty + postfix);\n}\n};\nsomeObject.myMethod('&lt;', '&gt;'); \/\/ alerts '&lt;Foo&gt;'\nvar someOtherObject  = {\n\n    myProperty : 'Bar.'\n\n};\nsomeObject.myMethod.call(someOtherObject, '&lt;', '&gt;'); \/\/ alerts '&lt;Bar&gt;'\n\nsomeObject.myMethod.apply(someOtherObject, ['&lt;', '&gt;']); \/\/ alerts '&lt;Bar&gt;'<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The function .call() and .apply() are very similar in their usage except a little difference&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1177"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=1177"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1177\/revisions"}],"predecessor-version":[{"id":1178,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1177\/revisions\/1178"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=1177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=1177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=1177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}