Jquery .each() - return value undefined

前端 未结 3 501
慢半拍i
慢半拍i 2020-12-12 04:51

Why getColorOptionSelect() return undefined value (I\'m sure it has a value by debugger ).

It is for sure an issue related to the scope, sorry for my js ignorance

3条回答
  •  星月不相逢
    2020-12-12 05:37

    getColorOptionSelect doesn't have an (uncommented) return statement.

    The only return statement you have is inside the anonymous function you pass to each(). It will be consumed by the code underlying each() (which will stop looping if it is false).

    This isn't a problem of scope, just of there being multiple functions.

    You probably want to:

    • define a variable before you call each()
    • assign a value to it inside the each loop
    • return that variable at the end of getColorOptionSelect

提交回复
热议问题