本身胡闹的代码函数
<script> function Fuck() { this.c={ ff:function () { return { hi:function () { return "." } } } } } var gz=new Fuck(); console.log(gz.c.ff().hi()); </script>
构造函数很简单,主要说一下这个thisthis
this表明构造函数被实例化以后的新对象,这里仅说明构造函数内的this,不表明其余地方的thisspa
构造函数的执行过程,就是不断的将属性和方法赋值给新对象this的过程。prototype
var Cteate = function () { this.a="11"; }; //添加静态成员 Cteate.str= "你好"; //访问静态成员 console.log(Cteate.str);
静态成员不可使用实例化的对象去调用,想要用实例化的对象去调用属性,也就是共享一个属性,叫作原型属性 prototypecode
var Create = function () { this.a="11"; }; //添加静态成员 Create.str= "你好"; //访问静态成员 console.log(Create.str); var obj=new Create();
//用prototype添加一个原型属性,用来共享这个属性 Create.prototype.ok=function () { return "ok ok "; }; var obj2=new Create(); console.log(obj.ok()); console.log(obj2.ok());