使用JSPatch时,OC转JS语法注意

来源:互联网 发布:示范性软件学院排名 编辑:程序博客网 时间:2024/06/05 06:05
  • OC常量替换
各种参数常量
  • 使用JSCovertor工具 OC转JS时,有些语法错误需要改,比如获取window时需要
var window = UIApplication.sharedApplication().delegate().window(); 一定注意⚠️ JSCovertor 转化时缺少delegate
  • 对于使用NSTimer时,获取时间戳,使用Math.floor()函数转换取整
if (Math.floor(self.timer().getTotal()/1000)!=0 && (Math.floor(self.timer().getTotal() / 1000)+1) % 5 == 0) {                self.startLogoShakeAnimation();            }
  • block 块内注意⚠️
var slf = self;block(){   slf.some......}
  • 属性需要注意、对于没有self.获取的属性,后面不是用()
var configDict = NSDictionary.alloc().init();// 带有self的使用()configDict = self.adCreationData().sceneAdConfig();// 下面没有使用()var yoffset = configDict.valueForKey("yOffset")/ 100.0;
  • 获取frame 或者 width注意去掉 orgin()
view.setFrame(CGRectMake(view.frame().x - moveLength, view.frame().y,            view.frame().width, view.frame().height));
  • @selector() 换成“”

基本的在 JSPatch gitHub上
https://github.com/bang590/JSPatch
https://github.com/bang590/JSPatch/wiki

0 0