zoukankan      html  css  js  c++  java
  • JavaScript Tutorial 02 #Object#

    var o3 = Object.create(Object.prototype); //equals new Object()
    //
    function inherit(p) {
        if(p==null) throw TypeError();
        if(Object.create) {
            return Object.create(p);
        }
    
        var t = typeof p;
        if(t!=="object" && t!=="function") throw TypeError();
        function f() {};
        f.prototype = p;
        return new f();
    }
    
    var o = {x:1}
    o.hasOwnProperty("x"); //true
    o.hasOwnProperty("y");
    o.hasOwnProperty("toString"); //false
    
    var o = {
        x: 1.0,
        y: 1.0,
        get r() {
            return Math.sqrt(this.x*this.x + this.y*this.y);
        },    
    }
    
    var serialnum = {
        $n : 0,
        get next() {
            return this.$n++;
        },
    }
    
    /* 给Object.prototype添加一个不可枚举的extend()方法 */
    Object.defineProperty(Object.prototype,
        "extend",
        {
            writable: true,
            enumerable: false,
            configurable: true,
            value: function(o) {
                var names = Object.getOwnPropertyNames(o);
                for(var i=0; i<names.length; i++) {
                    if(names[i] in this) continue;
                    var desc = Object.getOwnPropertyDescriptor(o,names[i]);
                    Object.defineProperty(this,names[i],desc);
                }
            }
        });
    
    /* prototype, class, extensible attribute */
    /* o.constructor.prototype */
    
    /* json */
    o = {x:1, y:{z:[false,null,""]}};
    s = JSON.stringify(o);
    p = JSON.parse(s);

  • 相关阅读:
    金融理财
    股权穿透图资料总结
    v-cloak指令用法
    前端跨域解决方案
    better-scroll
    vant-list实现下拉加载更多
    webpack原理
    .NET Framwork WebApi 添加swagger 在线接口文档步骤
    CORE API 限流,防止,链接数过多而崩溃。
    VS2019推送代码到GIT仓库
  • 原文地址:https://www.cnblogs.com/lambdatea/p/3376649.html
Copyright © 2011-2022 走看看