Javascript (二):Primitive Datatype

Primitive(原生的) datatype stored in memory stack.It’s value is literally copied(字面值复制).Even if change the original(原始的) value,the copied value remians unchanged.

  • string
  • number
  • boolean
  • undefined
  • null

When a primitive value is used as if it were an object created by a constructor, JavaScript converts it to an object in order to respond to the expression at hand,but then discards the object qualities and changes it back to a primitive value. In the code below, I take primitive values and showcase what happens when the values are treated like objects

    var pstr = “123”;
    pstr.toString();
    // pstr =>Object =>primitive

var pnum = 123;
pnum.toString();
// pnum =>Object =>primitive

var ostr = new String("123");
ostr.toString();
// ostr =>primitive

var onum = new Number(123);
onum.toString();
//onum =>primitive

 

Javascript (一):Functions As First-Class Things

The term “first-class” means that something is just a value. A first-class function is one that can go anywhere that any other value can go—there are few to no restrictions. A number in JavaScript is surely a first-class thing, and therefore a first-class function has a similar nature.

术语“first-class”仅表示一个数值,基础类Function可以出现“数值”能出现的任何地方(几乎没有限制)。number确实基础类在javascript中,因此基本类Function有相似的特性:

  • a number can be stored in a variable and so can a function

    var fortytwo = function() { return 42 };
  • a number can be stored in an object field and so can a function:

    var fortytwos = [42, function() { return 42 }];
    
  • a number can be stored in an object field and so can a function:

    var fortytwos = {number: 42, fun: function() { return 42 }};
  • a number can be created as needed and so can a function:

    42 + (function() { return 42 })();
    //=> 84
  • a number can be passed to a function and so can a function:

    function weirdAdd(n, f) { return n + f() };

weirdAdd(42, function() { return 42 }); //=> 84

  • a number can be returned from a function and so can a function:
    return 42;
    return function() { return 42 };
    
     

 

诗词摘录《江城子·乡愁》

《江城子·乡愁》

 

–摘录 赵小明(乐清人)《江城子·乡愁

飞星赶月梦中游。

白沙鸥、黑耕牛。

秋雨春风,花树满山丘。

少小欢声追蝶路,关帝庙、状元楼。

乡关万里载乡愁。

断难休,重悠悠。

海角天涯何处一云收?

最是空巢老父母,言未出,泪先流。