首页 > 代码库 > JavaScript with

JavaScript with

function Animal() {    this.name = ‘xxx‘;    this.id = 1;}var animal = new Animal();with(animal) {  // 括号内可以不用 ‘对象.属性‘,直接用属性名或方法    alert(name);    alert(id);}

 

JavaScript with