簡體   English   中英

我們怎么知道 Objective-C 中的 JSContext 可以下標?

[英]How do we know JSContext in Objective-C can do subscripting?

有很多這樣的示例代碼:

JSContext *context = [[JSContext alloc] init];
        context[@"globalFunc"] =  ^() {
        NSArray *args = [JSContext currentArguments];
        for (id obj in args) {
            NSLog(@"got:%@", obj);
        }
    };

讓我困惑的是context[@"globalFunc"] = ***聲明。 看起來 JSContext 支持下標(運算符 [ ])?

但是我沒有找到任何官方文件這么說? 那么我們如何知道我們可以在 JSContext 中進行下標以從中設置/獲取對象呢?

好的,我錯過了 JSContext 聲明后的擴展代碼-_-

@interface JSContext (SubscriptSupport)

/*!
@method
@abstract Get a particular property on the global object.
@result The JSValue for the global object's property.
*/
- (JSValue *)objectForKeyedSubscript:(id)key;

/*!
@method
@abstract Set a particular property on the global object.
*/
- (void)setObject:(id)object forKeyedSubscript:(NSObject <NSCopying> *)key;

@end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM