Closed DropDev closed 10 years ago
Done. e4032b27f72b6d97d370414904e41188ba1fcd45
Please try it.
For example:
var MyView = JSB.defineClass('MyView : UIView', {
// instance methods
touchesBeganWithEvent: function(touches, ev) {
JSB.dump(touches);
JSB.dump(ev);
return;
}
}, {
// class methods
layerClass: function() {
return CAGradientLayer;
}
});
i can confirm that it is not working yet.
Please show the sample code?
I checked at least above code is working.
defineClass
is create Objective-C class, to interacting system frameworks (delegates, datasources, and so on).
If you are creating JavaScript object, just use JavaScript syntax.
this did not show, the + methods did not work for example.
var MyView = JSB.defineClass('MyView : UIView', { // instance methods touchesBeganWithEvent: function(touches, ev) { JSB.dump(touches); JSB.dump(ev); return; } }, { // class methods layerClass: function() { return CAGradientLayer; } });
the method + layerClass did not work.
I added example code about overriding class methods.
It named gradientViewController.js
in UICatalog project.
https://github.com/kishikawakatsumi/JavaScriptBridge/blob/master/Examples/UICatalog/UICatalog/js/gradientViewController.js
It is simple example, it has a view controller and a view.
The view override + layerClass
class method to use CAGradientLayer
.
Please check it.
I think what you saying is: If define the class like shown below,
var MyButton = JSB.defineClass('MyButton : UIButton', {
}, {
buttonWithType: function(type) {
return UIButton.new();
}
});
var button = MyButton.buttonWithType(0); // Failed!!
MyButton
is the subclass of UIButton
overriding buttonWithType:
class method.
But invoking buttonWithType:
method fails.
Is this what you mean?
If I understand correctly, currently it is in the specifications.
The features like 'Class definitions' or 'Method overriding' are made for responding to system framework, such as delegates, data sources, UIViewContoller's methods, and so on.
Currently, JavaScriptCore has the limitation that is dynamically generated JSExport protocols does not work. It can not support because of the limitation.
In the file JSBScriptingSupport.m line 75 (method + (id)defineClass:instanceMembers:staticMembers: in) when you make a class method or known as a meta method it does not work because there is no coding their to add the class method after input of the staticMembers argument.