Example Analysis of this pointing problem in Promise
Editor to share with you the example analysis of this pointing problems in Promise, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Promisethis code
ClassDog {constructor () {this.name='adong';} start () {this.p () .then (this.say);} p () {returnnewPromise ((resolve,reject) = > {resolve ('good');})} say (str) {console.log (this); console.log (this.name+str);}} letdog=newDog (); dog.start ()
Promisethis error display
Undefined (node:5784) UnhandledPromiseRejectionWarning:TypeError:Cannotreadproperty'name'ofundefined atsay (D:\ NodeJS\ Test\ test2.js:18:22) classDog {constructor () {this.name='adong';} start () {this.p () .then (this.say.bind (this));} p () {returnnewPromise ((resolve,reject) = > {resolve ('good')) })} say (str) {console.log (this); console.log (this.name+str);}} letdog=newDog (); dog.start (); these are all the contents of the article "sample Analysis of this pointing to problems in Promise". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!