svg Namespace/eval/隐式类型转换/bind链式
私人笔记;只是自己看的懂就行;
postMessage
1、index.html:19 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://172.16.115.106:9099') does not match the recipient window's origin ('http://127.0.0.1:8848').
页面还没有创建好,需要延时之后 postMessage
堆栈误区纠正
栈内存分配是先进后出,堆是在运行的时候,请求操作系统分配给自己内存,堆无次序。
JSON
event Object -> json
vivus SVG
SVG写入image标签时,发现在google和火狐上无法显示,且报错: Namespace prefix xlink for href on script is not defined
后经查询,找到了解决办法:
在命名空间上添加:
xmlns:xlink=http://www.w3.org/1999/xlink
实例:
<pre style="box-sizing: border-box; outline: 0px; margin: 0px 0px 24px; padding: 8px; font-weight: normal; position: relative; white-space: pre-wrap; overflow-wrap: break-word; overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; color: rgb(0, 0, 0);"><?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
<image xlink:href="happy-every-day.jpg" width="96" height="96" />
</svg></pre>
其中 xmlns="http://www.w3.org/2000/svg" 的命名空间是使google、火狐浏览器兼容SVG的,
xmlns:xlink="http://www.w3.org/1999/xlink" 的部分是image标签适应google或火狐浏览器的。
module
module.exports、exports、require、export、export default、import
module.exports==exports //true (CMD规范,如node/seaJS) ----->对应的是require
export、export default---->对应的是import(ES6模块化规范)
作用域
正常模式下,Javascript语言有两种变量作用域(scope):全局作用域和函数作用域。严格模式创设了第三种作用域:eval作用域。
正常模式下,eval语句的作用域,取决于它处于全局作用域,还是处于函数作用域。严格模式下,eval语句本身就是一个作用域,不再能够生成全局变量了,它所生成的变量只能用于eval内部。
"use strict";
var x = 2;
console.info(eval("var x = 5; x")); // 5
console.info(x); // 2
问题记录
!![] == true //true
[]==false //true
![] == [] //结果是true
更多例子
[] == 0 //返回结果是 true
![] == 0 //返回结果是 true
[] == '' //返回结果是 true
!![] == '' //返回结果是 false
'' == true //返回结果是 false
解释
相等运算符(== ),两个操作数类型不同时,进行的转换;
[] 转为字符串是 "" // String([]) 返回""
[] 转为数字是 0 // Number([]) 返回0
[] 转为布尔值是 true // Boolean([]) 返回true
true 转为数字是 1 // Number(true) 返回1
false 转为数字是 0 // Number(false) 返回0
如果一个值是对象,另一个值是数字或字符串,则将对象转换为原始值,然后再进行比较。对象通过toString()方法或者valueOf()方法转换为相同类型原始值,JavaScript语言核心的内置类先尝试使用valueOf(),再尝试使用toString(),除了日期类,日期类只能使用toString()转换,那些不是JavaScript语言核心中的对象则通过各自的实现中定义的方法转换为原始值。
原始值:不可变更的值,包括undefined、null、布尔值、数字、和字符串。

bind
call && apply实现 bind
Function.prototype.my_bind = function(context){
var self = this;
return function(){
self.apply(context,arguments);
}
}
function a(){
console.log('name:',this.name);
}
a(); // ''
var b = {
name: 'apple'
};
var c = {
name: 'pear'
};
var d = {
name:'fruit'
}
a.my_bind(b).my_bind(c).my_bind(d)();
以上特别注意链式反应(也是bind的特性)