...

View Full Version : quick name conflict question



footballer27
01-07-2012, 12:18 AM
can I have a function and a variable be the same name in an object

for instance



function someObject(){
this.canDoSomething;//a boolean variable

function canDoSomething(){
//set this.canDoSomething;
return this.canDoSomething;
}
}


or will this be a naming conflict?
thanks

Old Pedant
01-07-2012, 12:49 AM
Not to ask a dumb question, but...

Why didn't you just try it?



<script>
function someObject(){
this.canDoSomething = true;//a boolean variable

function canDoSomething(){
//set this.canDoSomething;
return this.canDoSomething;
}
}

var so = new someObject();
alert( "variable: " + so.canDoSomething );
alert( "function: " + so.canDoSomething() );
</script>

Philip M
01-07-2012, 07:38 AM
can I have a function and a variable be the same name in an object


The answer is no, but even if it were possible it would be very poor practice to have identical names.

It is your responsibility to die() if necessary….. - PHP Manual

footballer27
01-07-2012, 09:58 PM
So, It will be a conflict? right? Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum