/* Title: 自我定义函数Description: 自身重写,以减少第一次调用以后的代码量*/var scareMe = function () {alert ( "Boo!" );scareMe = function () {alert ( "Double boo!" );};};// 1. 添加阴属性scareMe . property = "properly" ;var prank = scareMe ;var spooky = {boo : scareMe};prank (); // "Boo!"prank (); // "Boo!"console . log ( prank . property ); // "properly"spooky . boo (); // "Boo!"spooky . boo (); // "Boo!"console . log ( spooky . boo . property ); // "properly"// 使用自我定义函数scareMe (); // Double boo!scareMe (); // Double boo!console . log ( scareMe . property ); // undefined
Self-defining functions模式
最新推荐文章于 2023-03-08 16:29:01 发布