1. var f = function () {}
    2. // ES5
    3. // console.log(f.name);// f
    4. // console.log(new Function().name) // anonymous
    5. //
    6. // demo1
    7. function foo (){};
    8. foo.bind({});
    9. // console.log(foo.bind({}).name); // bound foo
    10. // 对象简写
    11. const foo = "bar";
    12. const baz = {foo}; // => {foo:"bar"}
    13. // 函数中对象简写
    14. function foo (a, b){
    15. console.log({a, b});
    16. // let a = a, b = b;
    17. }
    18. foo(1,2);
    19. let foo = (a, b)=>({a,b});
    20. let age = '12'
    21. const person = {
    22. age,
    23. say(){
    24. console.log(this.age); // es6写法
    25. }
    26. }
    27. person.say();// 12
    28. /************************************************************************************/
    29. function foo(){
    30. console.log('foo');
    31. }
    32. function bar(){
    33. console.log('bar');
    34. }
    35. function baz(){
    36. console.log('baz');
    37. }
    38. let a = 1;
    39. const obj = {
    40. a,
    41. foo,
    42. bar,
    43. baz
    44. }
    45. module.exports.obj = obj;
    46. /************************************************************************************/
    47. // 接收
    48. const {a,foo,bar,baz} = reuqire('./root.js');//上面代码的地址
    49. console.log(a,foo(),bar(),baz());
    50. var arr = [1,2,3,4,5,6,7,8];
    51. console.log(arr[1] === arr['1'])//true
    52. /************************************************************************************/
    53. let obj = {};
    54. obj.foo = true;
    55. obj['f'+'o'+'o'] = false;
    56. obj.foo === obj['f'+'o'+'o'] // true
    57. /************************************************************************************/
    58. let a = "hello" ;
    59. let b = "world" ;
    60. let obj = {
    61. [a + b]: true,
    62. ['hello'+b]: 123,
    63. ['hello'+'world']: undefined
    64. }
    65. // 属性名会变成字符串
    66. /************************************************************************************/
    67. var myObj = {};
    68. myObj[true] = 'foo';
    69. myObj[3] ='bar';
    70. myObj[myObj] ='baz';// {[object Object]:"baz"}
    71. const a = {a:1};
    72. const b = {b:1};
    73. const obj = {
    74. [a]:"valueA",
    75. [b]:"valueB"
    76. }
    77. console.log(obj)//{[object Object] :"valueB"};
    78. const person = {
    79. sayName(){
    80. console.log('hello');
    81. }
    82. }
    83. console.log(person.sayName.name);// sayName
    84. // ES5 属性描述符
    85. let obj = {a: 2};
    86. console.log(Object.getOwnProperty(obj,"a"));
    87. /**
    88. * configurable 可配置的
    89. * enumerable 可枚举
    90. * writable 可写
    91. * value 值
    92. */
    93. let language = {
    94. set current(name){
    95. this.log.push(name);
    96. },
    97. log:[]
    98. }
    99. language.current = "English";
    100. language.current = "Chinese";
    101. var obj = {
    102. _b:0,
    103. get a(){
    104. return this._b;
    105. }
    106. set a(val){
    107. this._b = val;
    108. }
    109. }