1.创建特定类型的对象
2.js开发尽量用单引号
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script> var AA = { Constractor: function(huawen) { //先自己实例化对象 ,function中的函数指向的是function,不是外层字典。 if(!(this instanceof AA.Constractor)){ return new AA.Constractor(); } var me = this; me.huawen = "无"; if (huawen != undefined || huawen != null) me.huawen = huawen; me.suo = "小锁"; me.create = function() { return "花纹:" + me.huawen + "锁" + me.suo; } } } console.log(AA); var p = AA.Constractor("有花纹"); alert(p.create()); </script> </head> <body> </body> </html>
时间: 2024-10-12 23:59:48