类比 js Function 对象的 bind 的方法
:
var name = 'ys';
var getHeightFunc = getHeight.bind(null , name);
var info = combineInfo(name , getHeightFunc);
console.log(name + ' 的信息:' , info);
function getHeight(name){
var person = {
'cxl' => 167 ,
'ys' => 165
};
var k;
for (k in person)
{
if (k === name) {
return person[k];
}
}
return false;
}
function combineInfo(name , getHeightFunc){
var name = typeof name !== 'string' ? '未定义名称' : name;
var height = getHeightFunc();
return {
name: name ,
height: height
};
}
PHP
函数如何实现上面的这种效果??
慕工程0101907
相关分类