function students() {
this.name = 'Jerry';
this.age = 18;
this.score = function(yuwen,shuxue,waiyu) {
return yuwen + shuxue + waiyu;
}
}
stu = new students();
//一般的寫法
stu.name = 'Jack';
stu.age = 28;
console.log("name : " + stu.name + ", age: " + stu.age + ", score : " + stu.score(85,90,92));
//使用with後,就相當於作用域此對象了
with(stu) {
name = 'tom';
age = 23;
console.log("name : " + name + ", age: " + age + ", score : " + score(60,80,50));
}
- <form onclick="return validForm(this);">
- <input type="text" name="username" id="username"/>
- <input type="submit"/>
- </form>
-
-
- function validForm1(formObj) {
- if(formObj.username.value == '') {
- console.log('username can not null.');
- return false;
- }
- }
-
-
-
- function validForm(formObj) {
- with(formObj) {
- if(username.value == '') {
- console.log('username can not null.');
- return false;
- }
- }
- }