that, self or me — which one to prefer in JavaScript?

前端 未结 3 939
挽巷
挽巷 2020-12-16 12:31

While coding JavaScript sometimes you store the reference of object this in a local variable for different purposes (to set proper scope, to help code obfuscato

3条回答
  •  爱一瞬间的悲伤
    2020-12-16 12:32

    There's an orange in your apple basket there, this has a very specific contextual meaning. The choice is really between self and me of those options. Between those...you choose, it doesn't matter either way only personal preference.

    this refers to the context your in, so it's not really an "option" without introducing a lot of confusion and easy to make errors. I see self used much more than me (in example code, frameworks, libraries, etc). It's just preference, but I agree self is more attractive, not sure why...again just my preference.

提交回复
热议问题