<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>With语句(类似于VB中的)</title>
<script type="text/javascript">
function Student(name, age) {
this.name = name;
this.age = age;
}
var stu = new Student('罗纳尔多', 36);
with (stu) { //With语句(类似于VB中的),用于简化代码
alert("Name:" + name + ",Age:" + age);
}
</script>
</head>
<body>
</body>
</html>
本文通过一个具体的示例介绍了如何使用With语句来简化JavaScript代码的编写过程。With语句允许开发者在一个作用域内引用对象的属性而不必重复指定对象名称,从而使得代码更加简洁易读。

被折叠的 条评论
为什么被折叠?



