console.log returns an additional undefined

后端 未结 1 1962
一生所求
一生所求 2021-01-16 17:47

I am trying to understand .bind and made the following code:

a simply object:

person = {
    name:\"Joe\",
    surname:\"Something\",
    tool:\"gun         


        
相关标签:
1条回答
  • 2021-01-16 18:24

    This has nothing to do with bind.

    When you call newPolice() it logs the result of this:

    console.log("You are under arrest, " + this.name + " " + this.surname);
    

    When you call console.log( newPolice() );, you now have two console.log statements which, between them, log:

    • The same thing as before
    • The return value of newPolice

    newPolice doesn't have a return statement, so it returns undefined.

    0 讨论(0)
提交回复
热议问题