Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of this pointing problem in Promise

Shulou Source: shulou.com Published: 2022-06-03 09:57:31 10月02日 Update

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!

Tags: Articles directions examples questions analysis content not much code most more knowledge industry information information channels errors channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info macOS Microsoft MariaDB