我想知道集成功能的方式是什么……我在下面放了4种方法。由于变量范围和/或声明方式,其中一种更好吗?也许其中一些或全部是完全错误的?任何帮助表示赞赏。非常感谢!
//method 1
var derpHerp1 = function() {
var addMe1 = function (firstNum,secNum){
var sum = firstNum + secNum;
return sum
}
return {
derp : 'derp',
herp : function(){
alert('herp');
},
adding : addMe1(5,6)
}
}();
//method 2 (2nd line & 3rd to the last changed)
var derpHerp2 = function() {
var addMe2 = function addMe2(firstNum,secNum){
var sum = firstNum + secNum;
return sum
}
return {
derp : 'derp',
herp : function(){
alert('herp');
},
adding : addMe2(5,6)
}
}();
//method 3 (2nd line & 3rd to the last changed)
var derpHerp3 = function() {
function addMe3(firstNum,secNum){
var sum = firstNum + secNum;
return sum
}
return {
derp : 'derp',
herp : function(){
alert('herp');
},
adding : addMe3(5,6)
}
}();
//method 4
function addMe4 (firstNum,secNum){
var sum = firstNum + secNum;
return sum
}
var derpHerp4 = function() {
return {
derp : 'derp',
herp : function(){
alert('herp');
},
adding : addMe4(5,6)
}
}();