学过盒子布局的人都知道,元素之间的上下margin会合并,保留数值较大的margin做为渲染依据.
可是今天在群里讨论发现:
img元素和p元素的上下margin不会合并.
这可能代表可替换元素和其余元素的margin存在本质区别.javascript
今天群里有人问我一个phpstorm提示的警告,代码以下php
$a=0; for($a;$a<20;$a++){ ...}
IDE对for循环中第一个变量$a
的警告信息为:Expression result unused
(表达式结果未使用)
然而实际运行是能够经过的.
通过一番思考和尝试,结论是: for循环中的第一个$a
没有赋值操做,也没有别的操做,因此会显示表达式未被使用.因此改为如下形式,就不会警告啦:css
$a=0; for(;$a<20;$a++){//去掉了初始化声明,就再也不警告. ...}
过去我判断奇偶基本靠除以2求余数来判断.
今天群里有人提了一个方法来判断奇偶:
按位与操做 代码&1==0
,返回 true就是偶数,返回false就是偶数.java
昨晚翻了一遍全部的Array.prototype
方法,想了一个新招来处理数组排序&去重,代码以下:程序员
function reducedup(array){ if(array.constructor.name!="Array"){ array=array.toString().split(""); } return array .sort(function (a,b) {return a-b;}) .filter(function (el,i,arr) { if((i<arr.length-1)&&el!==arr[i+1]|| (i==arr.length-1)&&el!==arr[i-1]){ return el;}}); } reducedup("8543217486765379534279089865314");
可调用对象不必定是函数对象
a function is referred to as a “callable object”—an object that has an internal [[Call]] property that allows it to be invoked.
函数是一个可调用对象,也就是说,是一个具备内建特性[call]
的对象,以致于让它能够被调用.编程It’s most appropriate to think of them also as a “subtype” of object (see Chapter 3), in this case with the additional characteristics of being numerically indexed (as opposed to just being string-keyed like plain objects) and maintaining an automatically updated .length property.
(数组)能够适当地把它想象成是Object类型的子类, 并加上了一些额外的性质,好比拥有可数下标,好比自动增加的.length属性.数组An “undefined” variable is one that has been declared in the accessible scope, but at the moment has no other value in it.
未定义变量是一个已经在特定做用域中被声明的,而还没有被赋值的变量.appfrom <You Don't know JS: type&grammar>phpstorm
String
也有concat
方法,操做规则和Array
同样.Array.from
能够直接转化一个伪数组为数组.Array.prototype.method.call(伪数组,etc)
的方式来对伪数组使用数组的方法String
也是一种伪数组,不过由于String
自己具备值的不可变性, 因此只能使用生成新数组的方法,而不能用改变String
自己的方法.Number.prototype.toFixed(int)
返回固定小数点int位置的值,而且转换为String
.Number.prototype.toPrecision(int)
也有一样效果,只不过他计算的是整个数值的长度.var a = 42.59; a.toFixed( 0 ); // "43" a.toFixed( 1 ); // "42.6" a.toFixed( 2 ); // "42.59" a.toFixed( 3 ); // "42.590" var a = 42.59; a.toPrecision( 1 ); // "4e+1" a.toPrecision( 2 ); // "43" a.toPrecision( 3 ); // "42.6" a.toPrecision( 4 ); // "42.59"
0.1+0.2!=0.3
的状况.function numbersCloseEnoughToEqual(n1,n2) { return Math.abs( n1 - n2 ) < Number.EPSILON;} var a = 0.1 + 0.2,b = 0.3; numbersCloseEnoughToEqual( a, b ); // true numbersCloseEnoughToEqual( 0.0000001, 0.0000002 ); // false
Number.MAX_VALUE
和Number.MAX_SAFE_INTEGER
是两回事.void
something
能够阻止赋值,替换为undefined
输出.(ES6)NaN
是数,但不存在相等性.也不能经过window.isNaN
来辨别,由于window.isNaN("b")
也返回true.Number.isNaN
复了这个bug.window.isNaN
为:isNaN = function(n) {return n !== n;};
Infinity *or+ Infinity //Infinity Infinity /or- Infinity //NaN Infinity/0 //Infinity Infinity*0 //NaN 1/Infinity //0 0/-3 //-0 JSON.stringify( -0 ); // "0" JSON.parse( "-0" ); // -0 -0===0 //true
You obviously must first convert (coerce)
the value from number to string.
显然地你必须首先将这个值从数值型(强制地)转换成字符型编程语言
to be considered a flaw in the design of the language, to be shunned
and avoided.
这被认为是一个语言设计时形成的失误,应当被避免和制止.
The value 42 has an intrinsic
type of number, and its type cannot be changed
数值42天生拥有number类型本质,而且没法被改变.
tempting for
most developers to think of the word “undefined” as a synonym
for “undeclared.”confound
you.However, a gotcha
to be aware of is that if a string value intended as a key can be coerced to a standard base-10 number
要明白的一点是,若是你想用一个字符串型的值做为键值,那它会被强制转换成10进制数.
Coerce
:强制,强迫;
Shunned
:避免,躲开;
intrinsic
固有的本质的;
tempting for
引诱,诱导;
synonym
同义词;
confound
:迷惑,困惑.
gotcha
:=got you=明白; 不写了...太麻烦,今天先到这里.