JSPatch之—动态新增 Property

来源:互联网 发布:淘宝号码购买 编辑:程序博客网 时间:2024/06/04 23:58

若要在 JS 为类新增 Property,可以使用 getProp() 和 setProp_forKey() 这两个接口。

注意 getProp() 无法获取在 OC 定义的 Property,只能获取在 JS 通过 setProp_forKey() 接口设置的 Property。

// OC
 
@interface JPTableViewController : UITableViewController
 @end
 @implementation JPTableViewController
 
@end
// JS
 
defineClass("JPTableViewController", { 
         init: function() {
             self = self.super().init() 
             self.setProp_forKey("JSPatch""data")  //添加新的 Property (id data)
            
 return self; 
         }, 
        viewDidLoad: function() {
              var data = self.getProp("data"//获取新的 Property 值 
         },
})
0 0