95
rated 0 times
[
96]
[
1]
/ answers: 1 / hits: 7193
/ 11 Years ago, thu, january 9, 2014, 12:00:00
Is there any difference when I explicitly return from a function vs. implicitly return?
Here's the code that puzzles me ATM:
function ReturnConstructor(arg){
// Private variable.
var privateVar = can't touch this, return ctor.;
// This is what is being exposed to the outside as the return object
return {
print: function() {
console.log(ReturnConstructor: arg was: %s, arg);
}
};
}
function NormalConstructor(arg){
// Private variable.
var privateVar = can't touch this, normal ctor;
// This is what is being exposed to the outside as public
this.print = function() {
console.log(NormalConstructor: arg was: %s, arg);
};
}
var ret = new ReturnConstructor(calling return);
var nor = new NormalConstructor(calling normal);
Both objects ('ret' & 'nor') seem the same to me, and I'm wondering if it's only personal preference of whomever wrote whichever article I've read so far, or if there's any hidden traps there.
More From » function