JavaScript Why is .map() not a function when using Array.prototype.slice.call()? [duplicate] function using array in c,function using pointer in c,

I noticed a weird thing in javascript. Consider the below:

var fn = ''.toUpperCase.call
console.log(typeof fn); // "function"
fn(); // Uncaught TypeError: `fn` is not a function

The above was executed on my Chrome's Developer Console. Version is 43.0.2357.81 m.

The typeof operator clearly shows that fn is a function, but the error suggests otherwise.

I've noticed that Function.apply shows at least some meaningful error message.

So, when is a function, not a function?

Answer:1

deceze's answer is correct, I just want to explain it from a different point of view.

Your fn is a reference to Function.prototype.call which needs to be called with a function as its this reference, in this case, the context for call is String.prototype.toUpperCase, which was inherited through ''.toUpperCase

On top of that, String.prototype.toUpperCase also has to be called with a specific context, the string to upper case.

Here's another way to code what you wanted that may help you understand what is going on.

    var str = 'aaa';
    var upper = ''.toUpperCase;
    var fn = upper.call;
    // Now we have to specify the context for both upper and fn
    console.log( fn.call(function() { return upper.call(str)}) ); // AAA
Answer:2

I'm using an asp.net list view control and within it I'm building a table element. <asp:ListView ID="ListView1" runat="server"> <LayoutTemplate> <table> <...

I'm using an asp.net list view control and within it I'm building a table element. <asp:ListView ID="ListView1" runat="server"> <LayoutTemplate> <table> <...

  1. jquery return table
  2. jquery return table row
  3. jquery return table row data
  4. jquery ajax return table
  5. jquery return html table
  6. jquery return data in table
  7. jquery ajax return html table

How do I add an auto-incremented build number into an about screen? By that I mean I want part of my version number auto-generated e.g. v2.2.0018 where "v2.2" is manually decided and "0018" is based ...

How do I add an auto-incremented build number into an about screen? By that I mean I want part of my version number auto-generated e.g. v2.2.0018 where "v2.2" is manually decided and "0018" is based ...

  1. auto increment build number xcode
  2. auto increment build number visual studio 2019
  3. auto increment build number visual studio
  4. auto increment build number jenkins
  5. auto increment build number maven
  6. auto increment build number
  7. auto increment build version
  8. auto increment build number xcode 9
  9. auto increment build number c#
  10. auto increment build xcode
  11. auto increment build number android studio
  12. auto increment build number gradle
  13. auto increment build number eclipse
  14. auto increment build version c++
  15. azure devops auto increment build number
  16. msbuild auto increment build number
  17. gradle auto increment build version
  18. fastlane auto increment build number
  19. unity auto increment build number
  20. cmake auto increment build number

I have the following HTML below that shows a list. HTML: <div id="Footer"> <ul> <li><a href="#" title="AGB">AGB</a></li> <li><a href="#" title="...

I have the following HTML below that shows a list. HTML: <div id="Footer"> <ul> <li><a href="#" title="AGB">AGB</a></li> <li><a href="#" title="...

I do the following $scope.product.orders.forEach(function (order) { $scope.$watch('order.details.items.length', function (n, o) { if (n !== o) { //do something } });...

I do the following $scope.product.orders.forEach(function (order) { $scope.$watch('order.details.items.length', function (n, o) { if (n !== o) { //do something } });...

  1. angular watch loop
  2. angularjs watch loop