您的位置:首页 > Web前端 > JavaScript

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

2016-08-03 09:16 357 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript JSPatch