zoukankan      html  css  js  c++  java
  • js练习 原型

            //var a = {
            //    fun: function a() {
            //        test = 0;
            //        alert(this);
            //        b();
            //        function b() {
            //            alert(this);
            //            var v = 0;
            //        }
            //    }
            //};
            //a.fun();

            Function.prototype.method = function (name, func) {
                //alert(this);
                this.prototype[name] = func;
                return this;
            };
            var test = function () {
                this.value = 0;
                alert('test');
            }
            test.prototype.method1 = function () {
                alert('method1');
            };
            
            //var method1= Function.method("method1", function () {
            //    alert('method1');
            //    alert(this);
            //    method2();
            //    function method2() {
            //        alert(this);
            //    }
            //})
            //test.method1();


            var test2 = function () {

            };
            test2.prototype = new test();
            var test2Instance = new test2();
            alert(test2Instance.value);

            //test.method1();

            //alert('1');
            //Function.method1();
            //method1.method1();

  • 相关阅读:
    【入门OJ】2003: [Noip模拟题]寻找羔羊
    vue history模式 ios微信分享坑
    JS预解释
    vuex存储和本地存储(localstorage、sessionstorage)的区别
    call、apply、bind
    正则表达式常用元字符
    微信公众号自定义菜单跳转到相关联小程序
    javaScript运动框架之缓冲运动
    javaScript运动框架之匀速运动
    js事件冒泡、阻止事件冒泡以及阻止默认行为
  • 原文地址:https://www.cnblogs.com/qook/p/5345431.html
Copyright © 2011-2022 走看看