What does “with” do in JavaScript?

前端 未结 8 1694
北荒
北荒 2020-12-28 18:06

I saw JavaScript code which begins with with. That\'s a bit confusing. What does it do and how can it be used correctly?

with (sObj) return opti         


        
8条回答
  •  忘掉有多难
    2020-12-28 18:17

    I would recommend NOT using this because of performance issues, but what the above means is:

    for the object sObj (here presumably a select element), all children and properties referenced on this one (or between following curly braces) treat that as their parent scope.

提交回复
热议问题