Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

javascript - Why does my code only throw an error when debugger is not attached?

Have you ever had such a problem? Your code works with debugger on but when it is off it doesn't work??

https://osaintilien55-gmail.tinytake.com/tt/NDk5MTE2MF8xNTcxNDI2Nw - Without Debugger

https://osaintilien55-gmail.tinytake.com/tt/NDk5MTE2M18xNTcxNDMwMw - With Debugger

So above I have 2 links to screen recordings, showing how when debugger is active my code works but when not it throws an error. If anyone is brave enough to look at my codepen of the issue I would be grateful. (Debugger doesn't work in codepen but if you were to take the code and put it in your editor you will see that it workers when debugger is on.) https://codepen.io/oliver-saintilien/pen/jOrQBLv

stackoverflow says that I MUST include code whenever I use a codepen link, however the code is a bit involved. So I will just post the code where there error occurs, but just remember it actually works if I have debug attached.

//Uses path to return nested object
const traverse = (obj, path) => {
  console.log(`1 time`);
  return path.split(".").reduce((object, key) => object[key], obj);
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For some reason by changing

let parentFolder = this[0].outerText.replace(/s/g, '')

to

let parentFolder = this[0].text.replace(/s/g, '')

causes it to work now without debugger on although I do not know why, but hey it works. Just to be clear, my using the method .text instead of .outerText is what made the difference.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...