!function(){}()

function后的();表示要执行这个函数。所以要求后面这个括号()前面必须是一个表达式。
所以!的作用是将function(){…}函数体转为一个函数表达式

其中两种常用的写法是:

(function() {
  ...
})();
const aa = function() {
  console.log('dd')
};
aa();

除此之外,还有其他几种可将function转为函数表达式:

!function () { /* ... */ }();
~function () { /* ... */ }();
-function () { /* ... */ }();
+function () { /* ... */ }();
void function () { /* ... */ }();
(function (){/*...*/}());
(function (){/*...*/})();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
完成CTime时间类和CDate日期类的设计,使得主程序能够正确运行。 时间类CTime包含私有成员数据时(hour)分(minute)秒(second),均为int类型。 CDate日期类由CTime时间类公有派生而来,包含私有成员数据年(year)月(month)日(day),均为int类型。 main函数已给定,提交时只需要提交main函数外的代码部分。 #include<iostream> using namespace std; //你提交的代码在这里 int main() { int dy,dm,dd,th,tm,ts; cin>>dy>>dm>>dd>>th>>tm>>ts; CTime t1; cout<<"[T1]"; t1.Show(); CDate d1; cout<<"[D1]"; d1.Show(); CDate d2(dy,dm,dd); cout<<"[D2]"; d2.Show(); CDate d3(dy,dm,dd,th,tm,ts); cout<<"[D3]"; d3.Show(); CDate d4(dy,dm,dd,t1); cout<<"[D4]"; d4.Show(); CDate d5(t1); cout<<"[D5]"; d5.Show(); return 0; } Input 1行,包含6个整数,分别代表年,月,日,时,分和秒。 Output 输出包含4行,具体输出格式参照样例。 Sample Input 1 1949 10 1 16 28 37 Sample Output 1 Function #1 is called! [T1]9:10:11 Function #3 is called! Function #1 is called! Function #4 is called! [D1]2023-4-5 9:10:11 Function #3 is called! Function #9 is called! Function #1 is called! Function #5 is called! [D2]1949-10-1 9:10:11 Function #3 is called! Function #9 is called! Function #2 is called! Function #6 is called! [D3]1949-10-1 16:28:37 Function #3 is called! Function #9 is called! Function #0 is called! Function #7 is called! [D4]1949-10-1 9:10:11 Function #3 is called! Function #9 is called! Function #0 is called! Function #8 is called! [D5]2000-12-31 9:10:11 Function #3 is called! Function #9 is called!
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值