What does “with” do in JavaScript?

前端 未结 8 1676
北荒
北荒 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条回答
  •  萌比男神i
    2020-12-28 18:16

    In that with block you dont have to type:

    sObj.options[selectedIndex].value
    

    but you can just use:

    options[selectedIndex].value
    

提交回复
热议问题