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

  • 相关阅读:
    pyqt-QGrapicsView类
    pyqt5.0 GraphicsView框架
    STM32(三)- GPIO输入输出之按键检测点亮LED
    STM32(二)- 位带操作、启动文件讲解
    STM32(一)- 基于固件库的工程模板
    C语言(四)- C预处理和C库
    C语言(三)- 结构体、结构体指针、位运算
    C语言(二)- 函数、指针、数组
    C语言(一)- 基础知识
    [caffe笔记]:杀死caffe多个进程中的某个(发生 leveldb lock 解决方法)
  • 原文地址:https://www.cnblogs.com/sw1990/p/5907682.html
Copyright © 2011-2022 走看看