UNPKG

0216tool_xiaoye

Version:

叶永洁自定义工具函数库

39 lines (37 loc) 1.37 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>12_自定义new和instanceof工具函数</title> </head> <body> <script src="../dist/yeyongjie.js"></script> <script> /** * * 1. 自定义new工具函数 语法: newInstance(Fn, ...args) 功能: 创建Fn构造函数的实例对象 实现: 创建空对象obj, 调用Fn指定this为obj, 返回obj 2. 自定义instanceof工具函数 语法: myInstanceOf(obj, Type) 功能: 判断obj是否是Type类型的实例 实现: Type的原型对象是否是obj的原型链上的某个对象, 如果是返回tru, 否则返回false */ function Fn (name,age){ this.name = name this.age = age } let p = new Fn('叶',12) console.log(p) console.log(Fn) console.log(Fn.prototype) let p2 = xiaoYe.newInstance(Fn,'叶',12) console.log(p2,p2.name) console.log(xiaoYe.myInstanceof(p,Object)) //true console.log(xiaoYe.myInstanceof(Fn,Function)) //true console.log(xiaoYe.myInstanceof(p,Function)) //false </script> </body> </html>