https://www.cnblogs.com/xinxue/p/5471708.html


C类型强制转换   形式:(type)objecttype(object)

最好是使用type(object);原因是:在某些编译器下,(type)object不会调用构造函数,而type(object)下则肯定会调用构造函数

C类型强制转换会按照以下顺序进行尝试转换:

a. const_cast
b. static_cast
c. static_cast, then const_cast
d. reinterpret_cast
f. reinterpret_cast, then const_cast



1 分析: 函数为何要有名字? 是为了方便下次使用. 匿名函数, 即没有名字.  

2 用途: 通常不希望再次使用(即只使用一次的)的函数可以定义为匿名函数. 

3 使用示例: 

1
2
3
4
5
// 定义并使用一个匿名函数来打印从1到10的整数
(function (n) {
    for (var i = 1; i <= n; i++)
        console.log(i);
})(10);

4 扩展: 当然, 如果还是想再次使用匿名函数的话, 也有方法. 即把匿名函数赋给一个变量(funtion类型的变量), 想再次使用时, 使用该变量来调用即可.示例如下: 

1
2
3
4
5
6
7
8
// 定义一个匿名函数并将它赋给变量printN
var printN = function (n) {
    for (var i = 1; i <= n; i++)
        console.log(i);
};
 
// 通过变量printN来再次使用该匿名函数
printN(10);

5 运行效果果图如下:

override

图1


override


相关文章:

  • 2022-12-23
  • 2021-09-21
  • 2021-06-11
  • 2021-05-24
  • 2021-05-27
  • 2021-11-17
  • 2021-10-17
  • 2022-01-26
猜你喜欢
  • 2021-06-03
  • 2021-10-08
  • 2021-09-28
  • 2021-10-29
  • 2021-09-23
相关资源
相似解决方案