var a = function(){};
var b = function(){};
alert(a == b);a = b;
alert(a == b);var a = [1];
var b = [1];
alert(a == b);a = b;
alert(a == b);看上面的例子,对象类型(object)不象string、number、boolean类型比较内容,而是比较地址;按楼主的想法可以这样比较:
alert(BillGates.SayHello.toString() == SteveJobs.SayHello.toString());
var b = function(){};
alert(a == b);a = b;
alert(a == b);var a = [1];
var b = [1];
alert(a == b);a = b;
alert(a == b);看上面的例子,对象类型(object)不象string、number、boolean类型比较内容,而是比较地址;按楼主的想法可以这样比较:
alert(BillGates.SayHello.toString() == SteveJobs.SayHello.toString());
alert(typeof(a));
alert(typeof(b));
非常好的例子。不过我现在又陷入了对象地址的疑团,嘿嘿
这里的对象地址是不是指变量的作用区域 eg:全局变量还是局部变量
code=JScript/
function Person(name)
{
this.name = name;
}; Person.prototype.SayHello = function()
{
alert("Hello,I'm" +this.name);
};
function Employees(name,salary)
{
Person.call(this,name); this.salary = salary; this.ShowMeTheMoney = function()
{
alert(this.name + "$" + this.salary);
};
}; Employees.prototype = new Person(); var BillGates = new Person("Bill Gates");
var SteveJobs = new Employees("Steve Jobs",1234); BillGates.SayHello();
//SteveJobs.SayHello();
SteveJobs.ShowMeTheMoney(); alert(BillGates.constructor);
alert(SteveJobs.constructor); alert(BillGates.SayHello == SteveJobs.SayHello);
alert(SteveJobs.SayHello);
alert(BillGates.SayHello);
[code]
function Person(name)
{
this.name = name;
}; Person.prototype.SayHello = function()
{
alert("Hello,I'm" +this.name);
};
function Employees(name,salary)
{
Person.call(this,name); this.salary = salary; this.ShowMeTheMoney = function()
{
alert(this.name + "$" + this.salary);
};
}; Employees.prototype = new Person();var BillGates = new Person("Bill Gates");
var SteveJobs = new Employees("Steve Jobs",1234); BillGates.SayHello();
SteveJobs.SayHello();
SteveJobs.ShowMeTheMoney(); alert(BillGates.constructor);
alert(SteveJobs.constructor); alert(BillGates.SayHello == SteveJobs.SayHello);
alert(SteveJobs.SayHello);
alert(BillGates.SayHello);