<iOS>typeof(self)的作用

block对于其变量都会形成strong reference,对于self也会形成strong reference,而如果self本身对block也是strong reference的话,就会形成strong reference循环,造成内存泄露,为了防止这种情况发生,在block外部应该创建一个week(__block)reference。

所以在block内如果有self的话,一般都会在block外面加一句__block typeof(self)bself = self;

__block typeof(self) bself = self;

[self methodThatTakesABlock:^{

    [bself dosomething];

}];

打印window--uni {}[[Prototype]]: Objectconstructor: &fnof; Object()hasOwnProperty: &fnof; hasOwnProperty()isPrototypeOf: &fnof; isPrototypeOf()propertyIsEnumerable: &fnof; propertyIsEnumerable()length: 1name: "propertyIsEnumerable"arguments: (…)caller: (…)[[Prototype]]: &fnof; ()[[Scopes]]: Scopes[0]toLocaleString: &fnof; toLocaleString()toString: &fnof; toString()valueOf: &fnof; valueOf()__defineGetter__: &fnof; __defineGetter__()__defineSetter__: &fnof; __defineSetter__()__lookupGetter__: &fnof; __lookupGetter__()__lookupSetter__: &fnof; __lookupSetter__()__proto__: (…)get __proto__: &fnof; __proto__()set __proto__: &fnof; __proto__() Window {0: Window, window: Window, self: Window, document: document, name: '', location: Location, …} chunk-vendors.js:5835 [WDS] Disconnected!markerObj.on('click', () => { console.log('window--uni', uni, window); // console.log(marker, '000'); // 将数据转为字符串 const message = JSON.stringify({ type: 'markerClick', title: marker.title }); window.parent.postMessage(message, '*'); // 通过uni.postMessage发送数据 // uni.postMessage({ // data: JSON.stringify(message) // 发送字符串 // }); });为什么在uniapp的 hybrid/html下面有一个map.html,在map.html中引入了<body> <div id="map-container"></div> <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.0.1.52.js"> </script> <script> window._AMapSecurityConfig = { securityJsCode: 'cf331d54f67e306ca5c0b17f7122d559' }; </script> <script src="https://webapi.amap.com/maps?v=2.0&key=f3323c24769b10828db07f07c0fcec0d&plugin=AMap.MarkerCluster"> </script>,然后点击无法获取到 uni.postMessage
最新发布
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值