+ webScriptNameForKey:
+ webScriptNameForSelector:
+ isSelectorExcludedFromWebScript:
+ isKeyExcludedFromWebScript:
WebScripting
is an informal protocol that defines methods that classes can implement to export their interfaces to a WebScript environment such as JavaScript.Technology
Not all properties and methods are exported to JavaScript by default. The object needs to implement the class methods described below to specify the properties and methods to export. Furthermore, a method is not exported if its return type and all its parameters are not Objective-C objects or scalars.
Method argument and return types that are Objective-C objects will be converted to appropriate types for the scripting environment. For example: 例えば:
nil
is converted to undefined.
NSNumber
objects will be converted to JavaScript numbers.
NSString
objects will be converted to JavaScript strings.
NSArray
objects will be mapped to special read-only arrays.
NSNull
will be converted to JavaScript’s null
.
Web
will be converted to undefined.
Web
instances will be unwrapped for the scripting environment.
Instances of all other classes will be wrapped before being passed to the script, and unwrapped as they return to Objective-C. Primitive types such as int
and char
are cast to a numeric in JavaScript.
Access to an object’s attributes, such as instance variables, is managed by key-value coding (KVC). The KVC methods set
and value
are used to access the attributes of an object from the scripting environment. Additionally, the scripting environment can attempt any number of attribute requests or method invocations that are not exported by your class. You can manage these requests by overriding the set
and value
methods from the key-value coding protocol.
Exceptions can be raised from the scripting environment by sending a throw
message to the relevant Web
instance. The method raising the exception must be within the scope of the script invocation.
+ webScriptNameForKey:
+ webScriptNameForSelector:
+ isSelectorExcludedFromWebScript:
+ isKeyExcludedFromWebScript:
- invokeDefaultMethodWithArguments:
- invokeUndefinedMethodFromWebScript:withArguments:
- finalizeForWebScript
WebScriptObject
WebScriptObject
object is an Objective-C wrapper for a scripting object passed to your application from the scripting environment.WebUndefined
WebUndefined
objects are simply used to represent the JavaScript “undefined” value in methods when bridging between JavaScript and Objective-C. For example, if you invoke a JavaScript function that returns the JavaScript “undefined” value, then a WebUndefined
object is returned to the Objective-C calling context.