anseki / leader-line

Draw a leader line in your web page.
http://anseki.github.io/leader-line/
MIT License
3.03k stars 425 forks source link

position() error #386

Closed yuleiQ closed 1 year ago

yuleiQ commented 1 year ago

when I call position(), display error, but I don't know why

image
window.addEventListener('scroll', () => {
      this.drawPosition();
    }, true);

drawPosition() {
      if (this.lines && this.lines.length) {
        this.lines.forEach(line => {
          line.position();
        });
      }
    },
anseki commented 1 year ago

Hi @yuleiQ, thank you for the comment. The this.lines seems to contain undefined. Your code has a bug maybe. However, of course I didn't read other parts of your code. For example, that checks this.lines.length wastefully, you can replace the line with:

      if (this.lines) {

Because the .forEach() method does nothing when the array is empty.

anseki commented 1 year ago

This may help you: https://jsfiddle.net/xqd92ke8/

yuleiQ commented 1 year ago

Hi @yuleiQ, thank you for the comment. The this.lines seems to contain undefined. Your code has a bug maybe. However, of course I didn't read other parts of your code. For example, that checks this.lines.length wastefully, you can replace the line with:

      if (this.lines) {

Because the .forEach() method does nothing when the array is empty.

I tried, it seems that it is not because of the error here, because my lines are an array

anseki commented 1 year ago

Try this example code: https://github.com/anseki/leader-line/issues/386#issuecomment-1369781207 The forEach() problem is another problem of your code. That doesn't throw an error but it makes wrong behavior wastefully.

anseki commented 1 year ago

No reply came, then this abandoned issue is closed.