zoukankan      html  css  js  c++  java
  • 函数的原型链

    function HotTag(parent){
    //自动执行初始化(xxx,xxx)
    this.init(parent);//this--->remen remen.init()
    //remen--->remen.__proto__(HotTag.prototype)
    //return this;
    }
    //初始化
    HotTag.prototype.init=function(parent){
    //this-->remen(HotTag的实例)
    //1、初始化页面
    this.initDom(parent);//remen.__proto__
    //2、绑定事件
    this.bindEvents();//HotTag.prototype.bindEvent
    };
    HotTag.prototype.initDom=function(parent){
    //this--->remen
    //作为热门标签的容器
    var div=document.createElement("div");
    div.className="hottag-container";

    var h1=document.createElement("h1");
    h1.innerText="热门标签";

    var h3=document.createElement("h3");
    h3.innerText="内容。。。。。。。。。。";

    div.appendChild(h1);
    div.appendChild(h3);

    parent.appendChild(div);

    //将功能的容器作为对象的属性(目的:在其他方法中可以访问到容器-->可以访问到容器里面
    的元素)
    this.container=div;//设置remen对象的自有属性container
    };
    //绑定事件
    HotTag.prototype.bindEvents=function(){
    //this-->remen

    this.container.querySelector("h1").onclick=function(){
    alert("点击了热门标签");
    };
    this.container.querySelector("h3").onclick=function(){
    alert("点击了内容");
    };
    };

    var remen=new HotTag(document.body);

    函数的创建
    //声明式
    function f1(){} //new Function()
    //函数表达式
    var f2=function(){}; //new Function()

    //创建一个无参无返回值的函数
    var f3=new Function("var a=10;a++;console.log(a);console.log('你还好吗?')");

    //创建一个有一个参数的函数
    var f5=new Function("num1","console.log(num1);");
    //创建2个参数的函数
    var f6=new Function("a","b","console.log(a+b);");

    //a1,b1,c1--->a1++ b1+c1
    var f7=new Function("a1","b1","c1","a1++;console.log(a1);console.log(b1+c1);");


    //结论1:任何函数都是Function的实例
    function foo(){}
    //foo.__proto__===Function.prototype
    //Function.prototype.constructor===Function
    //Function--->本身就是一个函数:自己创建了自己

    //Array,构造函数,原型对象

    //结论2:Function.prototype继承自Object.prototype
    // Function.prototype.__proto__===Object.prototype

    //Function Function.prototype
    //Object Object.prototype

  • 相关阅读:
    DOM 文本节点 、节点列表
    haslayout综合【转】
    css兼容性详解
    重温textjustify:interideograph
    掌握三点即可轻松打造出良好的交互设计效果
    ASP.NET 中的正则表达式
    Net中的反射使用入门
    ASP.NET2.0页面状态持续[转]
    使用XmlTextWriter对象创建XML文件[转]
    判断SQLSERVER数据库表字段为空的问题
  • 原文地址:https://www.cnblogs.com/sw1990/p/5907682.html
Copyright © 2011-2022 走看看