Objective-c选择器,其他语言如c++, python, ruby, java, javascript有类似的东
objective-c selector, do other languages such as c++, python, ruby, java, javascript have similar thing?
// main.m
#import <Foundation/Foundation.h>
#import "Car.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Car *porsche = [[Car alloc] init];
porsche.model = @"Porsche 911 Carrera";
SEL stepOne = NSSelectorFromString(@"startEngine");
SEL stepTwo = @selector(driveForDistance:);
SEL stepThree = @selector(turnByAngle:quickly:);
// This is the same as:
// [porsche startEngine];
[porsche performSelector:stepOne];
// This is the same as:
// [porsche driveForDistance:[NSNumber numberWithDouble:5.7]];
[porsche performSelector:stepTwo
withObject:[NSNumber numberWithDouble:5.7]];
if ([porsche respondsToSelector:stepThree]) {
// This is the same as:
// [porsche turnByAngle:[NSNumber numberWithDouble:90.0]
// quickly:[NSNumber numberWithBool:YES]];
[porsche performSelector:stepThree
withObject:[NSNumber numberWithDouble:90.0]
withObject:[NSNumber numberWithBool:YES]];
}
NSLog(@"Step one: %@", NSStringFromSelector(stepOne));
}
return 0;
}
对于objective-c选择器,其他语言如c++, python, ruby, java, javascript有类似的东西吗?由于
是。c++有指向执行类似函数的成员的指针——这些指针可以识别一个实例方法,然后可以调用该实例方法,提供要调用该方法的对象和参数,类似的语义(模Objective-C使用动态绑定,c++使用延迟绑定),但语法与performSelector:withObject:
等不同。
别人?
相关文章:
- 如何在本地机器上运行c++和javascript客户端代码(hackerbank风格)
- 在java中解决这段代码时面临循环中的问题
- 尝试用java代码编译和运行c++代码
- 在这种情况下,java对象是否可以调用本机函数
- 如何将C++闭包与变量参数同时重用——类似于JavaScript
- 在java中读取c++字节的位字段
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- 使用已使用 java 编码的 openssl 解码数据
- 嘿,我正在尝试将此c ++转换为javascript,但有些东西不起作用
- SWIG Java 在使用 -DSWIGWORDSIZE64 时将int64_t转换为 jlong
- Android Java USB for native cpp
- 在由Sublime文本3编译后在cmd上显示Java程序输出
- C++ equivalent to Java Map getOrDefault?
- 使用 javascript 实现 Trade/Quote API(c++ 或 Java)
- Javascript/CSS/HTML/Java IDE?
- 为什么在MongoDB或CouchDB中使用Javascript而不是其他语言,如Java, c++
- 需要在HTML+JavaScript的客户端和Java/C++的服务器端程序之间进行通信
- Objective-c选择器,其他语言如c++, python, ruby, java, javascript有类似的东
- C++/JavaScript Unity3D with Java
- JavaScript, Java, Php或c++密码加密-修改算法