function test(message){
alert(message);
}
var f = test;
f('hello world');
var f = function(message){
alert(message);
};
f('hello world');
var f = new Function("message","alert(message);");
f('hello world');
function test(){
this.property = 'hello world';
}
test();
alert(window.property); //由于在全局范围内调用,test函数中的this实际指向全局对象(window)
var obj = {};
test.call(obj); //通过call第一个参数指定执行上下文范围,所以test函数中this指向obj实例。
alert(obj.property);
var obj2 = {};
obj2.test2 = test; //将obj2实例方法test指向 全局test方法
obj2.test2(); //由于是在obj2上调用test方法,所以test函数中的this也指向了obj2实例
alert(obj2.property);
function Person(){
this.name = 'xfrog';
this.Say = function(){
alert(this.name);
};
}
var p1 = new Person(); p1.Say();
Person(); Say(); window.Say();
var p1 = new Person(); var p2 = new Person(); var test = p1.Say == p2.Say;
function Person(){
this.name = 'xfrog';
this.Say = say;
}
function say(){
alert(this.name);
}
var p1 = new Person();
var p2 = new Person();
alert(p1.Say == p2.Say);
p1.name = 'wang';
p1.Say();
function Person(){
}
Person.prototype.name = 'xfrog';
Person.prototype.Say = function(){
alert(this.name);
};
var p1 = new Person();
var p2 = new Person();
alert(p1.Say == p2.Say); //返回true
function Person(){
this.name = 'wang';
}
Person.prototype.name = 'xfrog';
Person.prototype.Say = function(){
alert(this.name);
}
var p1 = new Person();
p1.Say(); //将返回wang
p1.__proto__["Say"]();
function Person(){
}
Person.prototype = {name:'xfrog', Say:function(){
alert(this.name);
}};
Person.prototype = {
constructor: Person,
name :'xfrog',
Say:function(){
alert(this.name);
}
}
function Person(){
}
Person.prototype = {
name: 'xfrog',
obj : { age: 18 },
Say : function(){
alert(this.obj.age);
}
};
var p1 = new Person();
var p2 = new Person();
p1.obj.age = 20;
p1.Say();
p2.Say();
function Person(){
this.obj = { age: 18 };
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有