PDA

View Full Version : [SOLVED] javascript apply funtion.......



abhilashm86
September 28th, 2009, 08:14 AM
i tried using apply in order to use a method in more than one object, why does this stop executing further more statements?

<html>
<head>
<title>fun objs</title>
</head>

<script type="text/javascript">
function a(color1)
{
this.color=color1;
this.saycolor= function()
{
alert(this.color);
};
}

function b(color2, name2)
{
a.apply(this,arguments);
this.color=color2;
this.name=name2;
this.sayname==function () {
alert(this.name);
};
}

var obja=new a("red");
var objb=new b("black","sadgh");
obja.saycolor();
objb.saycolor();
objb.sayname();

</script>
</html>


objb.sayname();

this is not getting executed?

CyberJack
September 28th, 2009, 08:44 AM
replace this.sayname==function () { to this.sayname = function () {
(double to single = character)

abhilashm86
September 28th, 2009, 09:43 AM
replace this.sayname==function () { to this.sayname = function () {
(double to single = character)

that was my bad mistake!! shoud'nt have posted:) in hurry, i din't see that!!