嗯,你明白这一切错误
Function.prototype.showMsg = function() {
alert("This is a sample message.");
};
function Person() {
this.name = "Mahesh";
};
var personObj = new Person();
personObj.prototype.showMsg();
首先你原型的功能类,然后创建名为Person的自定义类,然后创建Person的一个实例。然后,您呼叫的很蓝印页showMsg这是2个误区1个showMsg是无界到人,然后打电话给它,如果它的边界,你直接称呼它
personObj.showMsg()
意愿,使这个脚本从我的观点工作,如果我给你写 写像这样 - >
function Person() {
this.name = "Mahesh";
};
Person.prototype.showMsg = function() {
alert("This is a sample message.");
};
var personObj = new Person();
personObj.showMsg();
我的脚本绑定的showMsg直接Person类,如果你需要它通过Person对象,并通过功能类别为则你必须从函数类继承像这样
Function.prototype.showMsg=function() {
alert("This is a sample message.");
};
function Person() {
this.name = "Mahesh";
};
Person.prototype = Function;
Person.prototype.constructor = Person;
var personObj = new Person();
personObj.showMsg();
问候
'prototype'是构造函数,而不是构造的对象 – 2013-03-24 12:11:08
哦这就是有趣,所以我怎么能实现类似的? – Mahesha999 2013-03-24 12:13:59