我知道
javascript,例如支持函数内部的函数,如下所示:
function doSomething(){
function doAnothingThing(){
//this function is redefined every time doSomething() is called and only exists inside doSomething()
}
//you can also stick it inside of conditions
if(yes){
function doSomethingElse(){
//this function only exists if yes is true
}
}
}
Objective-c是否支持此功能?理论范例:
-(void) doSomething:(id) sender{
-(void) respondToEvent: (id) sender{
//theoretically? ... please?
}
}
奖励:“本地”功能的正确用语是什么?
解决方法
通常的术语是嵌套函数. gcc支持嵌套函数作为C的扩展(默认情况下禁用).我认为这个选项不适用于带有gcc的Objective-C(或C),即使它是使用它可能不是一个好主意(可移植性等).
gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html