日期:2014-05-16 浏览次数:20456 次
function ShowText(text)
{
this.word = text;
this.sing = function singFunction() {alert("HelloWorld!~");};
}
obj1 = new ShowText("sb1");
obj2 = new ShowText("sb2");
function ShowText()
{
this.sing = singFunction;
}
function singFunction(){ alert("HelloWorld!~"); }
new ShowText().sing();
function ShowText()
{
}
ShowText.prototype.sing = function(){ alert( "HelloWorld!~");}
new ShowText().sing();
function ShowText(text)
{
this.word = text;
}
var obj = new ShowText("hi,tomsui!~");
alert(obj.word); // "hi,tomsui!~"
var obj2 = new Object();
obj2.constuct = ShowText;
obj2.constuct("hi,tomsui!~");
alert(obj2.word); // "hi,tomsui!~"
var ball0=new Ball("creating new Ball");
<==>
var ball0=new Object();
ball0.construct=Ball;
ball0.construct("creating new ball");
function showText(text) { alert(test);}
// 下面证明了showText的prototype属性是对象
alert(typeof(showText.prototype)); // object
// 下面说明了showText.prototype这个对象不能用默认toString()打印
alert(showText.prototype); // [object, Object]
// 下面证明showText.prototype.constructor的存在性
alert(showText.prototype.constructor); // function showText(text) { alert(test); }
alert(typeof showText.prototype.constructor); // function
// 添加属性text属性
function showText() {};
showText.prototype.text = "HelloWorld!~";
// 添加shout()方法
function showText() {}
showText.prototype.shout = function(){alert("tomsui wants to smoke!~");};
function ShowText() {};
// 添加text属性
ShowText.prototype.text = "HelloWorld!~";
alert(new ShowText().text); // HelloWorld!~
// 添加shout()方法
ShowText.prototype.shout = function(){alert("tomsui wants to smoke!~");};
new ShowText().shout(); // tomsui wants to smoke!~