js中函数,其实也有属性,比如:

function myfunc(){
  return 888;
}

myfunc.length  //这个就是函数的属性

c++中实现时, obj_template->SetCallAsFunctionHandler(Myfunc); 这样实现的。类似java的类,就是一个函数类。不过它还多了属性。

myfunc.cat="miaomiao";
myfunc.dog="wangwang";

console.log(myfunc);//
console.log(myfunc()); //调的函数:888 
console.log(myfunc.cat); //miaomiao
console.log(myfunc.dog); //wangwang

 

对于对象模板:每个函数模板都有与之关联的对象模板,prototypeTemplate就是个对象模板;对象模板也能脱离函数模板使用。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-01-08
  • 2022-02-09
  • 2021-09-05
  • 2021-10-05
猜你喜欢
  • 2021-11-26
  • 2021-04-25
  • 2021-07-04
  • 2021-12-01
  • 2021-11-14
相关资源
相似解决方案