JSPatch心得

转载请注明来源

1 CGSize,CGPoint,CGRect的使用,直接调用x,y,width,height四个属性,而且不用加().
例子
defineClass('PZPhotoView', {
zoomRectForScale_withCenter: function(scale, center) {
var zoomRect = {x:0,y:0,0,height:0};
zoomRect.width = self.frame().width/ scale;
zoomRect.height = self.frame().height/ scale;
zoomRect.x = center.x - (zoomRect.width / 2.0);
zoomRect.y = center.y - (zoomRect.height / 2.0);
return zoomRect;
},
});

2 类方法覆盖,目前看无效.
3 日志输出
console.log("xxxx");
4 使用模式
建议客户端在执行成功后,缓存一下Patch内容,这样启动时就可以先读取缓存中的内容\,理论上就可以覆盖除了启动函数外的所有函数.
5 对象,使用时一定注意检查是不是无效对象.
6 写代码时,尽量减少变量,函数名中的下划线字样.
7 常量,可以写在一个公共的地方.
8 block,一定注意weakself的写法,否则block会出现各种各样的问题,千奇百怪.
var weakSelf = __weak(self);
9 数字,BOOL类型,不需要调用integerValue,boolValue之类的接口,自动转换了.
10 coredata部分函数读取目前是失败的,不确定原因.

原文地址:https://www.cnblogs.com/decwang/p/5213910.html