Get the App
SLTechnology News&Howtos  ›  Development  › 

What to do if stack overflow occurs in fast application in javascript

Shulou Source: shulou.com Published: 2022-06-01 05:01:18 09月30日 Update

This article mainly introduces the javascript fast application stack overflow how to do, the article is very detailed, has a certain reference value, interested friends must read it!

A short code snippet describes the problem where $element ('id') is assigned to a member variable and a stack overflow occurs, as well as a solution to fix it.

When assigning the acquired content $element ('id') to a member variable, RangeError: Maximum call stack size exceeded may have a stack overflow (), causing the program to crash. A stack overflow also occurs if a member variable reference exists in a DOM and the member variable changes. The sample code is as follows:

{{stateText}} export default {private: {mContentNode: null, stateText: 'init state'}, onReady () {/ * When data obtained by $element (' id') is assigned to a member variable, a stack overflow may occur. * / this.mContentNode = this.$element ('content')}, onTestClick () {/ * To reproduce this problem, change a member variable when member variable references exist for a DOM. * / this.stateText = 'new state'}}

The reason is that assignment can lead to massive changes in data. This results in an internal exception loop, resulting in a stack overflow.

Solution

To prevent stack overflows, you can assign the acquired data to $element ('id') local or global variables instead of member variables. The sample code is as follows:

Let $gContentNode = null export default {private: {stateText: 'init state'}, onReady () {/ * You can assign the data obtained through $element (' id') to a local or global variable to prevent the stack overflow. * / const cContentNode = this.$element ('content') $gContentNode = this.$element (' content')}, onTestClick () {this.stateText = 'new state'}} these are all the contents of the article "what to do about stack overflow in fast applications in javascript". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Variables stacks members code content what to do applications data scenarios examples articles solutions assignments changes brevity value overall interests reasons guys Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Redmi Docker Linux