sort some list elements into an descreasing ones in js

Intro

Sort is a prevalent topic in programing. Although the sort operation mostly is handled by the back-end like PHP, Java and so on, occasionaly some are occured in front-end. Here are some simple instances I dealt with recently.

Bubble-like Sort

Suppose some list elements ordered as follows:

1
2
3
4
5
6
<ul id="demo">
<li>2</li>
<li>1</li>
<li>4</li>
<li>3</li>
</ul>

Every time I filter through the nodes to get the smallest-value one from 1st one to 4nd one, and then I put it to the tail of lists. Next, I still filter to get the smallest-value one but from 1st one to 3nd one, and still put it to the tail to the lists. Now, two elements are sorted, and still two ones stay idle. The operation continues until all the elements have been sorted.
The produceres can be illustrated as follows:

2 1 4 3 -> 2 4 3 1 -> 4 3 1 2 -> 4 1 2 3 -> 1 2 3 4

在JS中实现静态变量/函数

静态变量/方法

静态变量/方法,一般来说是独立於对象的存在,它不属於任何一个具体的对象,它属於每一特定类的所有对象。也可以认为是属於一个类的。静态变量一般用於常数,或者存储某一类的所有对象需要共有的变量。
学JS的时候发现,与JAVA,C++相比,JS并没有明确定义静态的声明或使用方法。虽然没有说,但仍然需要,比如一个很经典的需要就时用静态变量统计一个类被实例化了几次。

在初学JS时犯的一些错误

表示最近在学JS, 相对个人以前学的Python, JAVA之类的语言, JS的语言确实有一些”奇葩”. 把初学时的一些语法错误记录下来,方便自己以后查阅, 如果能帮助到读这篇文章的你自然就更好了.

number 与 string 相加/减/乘/除

Example 1:

1
2
var a  = "5" + 2;   // the result is "52"
var b = 2 + "5"; // the result is "25"