WebScripting Protocol Reference の webScriptNameForSelector: に書いてあった。

It is your responsibility to ensure that the returned name is unique to the script invoking this method. If this method returns nil or you do not implement it, the default name for the selector is constructed as follows:

・A colon (“:”) in the Objective-C selector is replaced by an underscore (“_”).

・An underscore in the Objective-C selector is prefixed with a dollar sign (“$”).

・A dollar sign in the Objective-C selector is prefixed with another dollar sign.



- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
    WebScriptObject *windowObject = [[sender mainFrame] windowObject];
    [windowObject setValue:self forKey:@"appObject"];
    NSString *message = @"call from Objective-C";
    [windowObject evaluateWebScript:[NSString stringWithFormat:@"test('%@');",message]];

- (void)myTest:(NSString *)message
    NSString *result=[message stringByAppendingString:@" append myTest string"];
    //call from Objective-C append JavaScript string append myTest string

+ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector
    return NO;
function test(message) {
  var string = " append JavaScript string";