当前位置: 首页 > news >正文

网站设计原则的历史视觉设计师是做什么的

网站设计原则的历史,视觉设计师是做什么的,网站建设招标书范本,wordpress数据类型Reflect 对象是 JavaScript ES6 中引入的一个内建对象,它提供了一系列与对象操作相关的方法。这些方法与 Object 对象上的方法类似,但在行为上有一些差异,并且更加规范和统一。Reflect 对象并不是一个构造函数,不能被 new 操作符调…

Reflect 对象是 JavaScript ES6 中引入的一个内建对象,它提供了一系列与对象操作相关的方法。这些方法与 Object 对象上的方法类似,但在行为上有一些差异,并且更加规范和统一。Reflect 对象并不是一个构造函数,不能被 new 操作符调用,它是一个静态对象,所有方法都是静态方法。

Reflect 对象的详细方法与示例

  1. Reflect.get(target, propertyKey[, receiver])

    • 作用: 读取对象的属性值。

    • 示例:

    const obj = {name: 'Alice',age: 25,get greeting() {return `Hello, ${this.name}!`;},
    };const protoObj = {city : 'New York'
    }Object.setPrototypeOf(obj, protoObj);console.log(Reflect.get(obj, 'name'));           // 输出: Alice (获取自身属性)
    console.log(Reflect.get(obj, 'age'));            // 输出: 25
    console.log(Reflect.get(obj, 'greeting'));      // 输出: Hello, Alice! (访问 getter)
    console.log(Reflect.get(obj, 'city'));           // 输出: New York (访问原型属性)const obj2 = {name: 'Bob',
    }// 使用 receiver 修改 getter 函数的 this 指向
    console.log(Reflect.get(obj, 'greeting', obj2)); // 输出: Hello, Bob!
    
  2. Reflect.set(target, propertyKey, value[, receiver])

    • 作用: 设置对象的属性值。

    • 示例:

    const obj = {name: 'Charlie',set age(newAge) {this._age = newAge},
    };
    const obj2 = {}
    Object.setPrototypeOf(obj, obj2)console.log(Reflect.set(obj, 'name', 'David')); // 输出: true
    console.log(obj.name);                       // 输出: DavidReflect.set(obj, 'age', 30);  // 设置 setterconsole.log(obj._age); // 输出: 30Reflect.set(obj, 'age', 35, obj2) // setter 的 this 绑定为 obj2
    console.log(obj2._age); // 输出: 35
    
  3. Reflect.has(target, propertyKey)

    • 作用: 检查对象是否包含指定的属性(包括原型链上的)。
    • 示例:
    const obj = { name: 'Eve', age: 20 };
    const protoObj = {city : 'London'
    }
    Object.setPrototypeOf(obj, protoObj)
    console.log(Reflect.has(obj, 'name'));   // 输出: true
    console.log(Reflect.has(obj, 'age'));    // 输出: true
    console.log(Reflect.has(obj, 'city'));   // 输出: true
    console.log(Reflect.has(obj, 'address')); // 输出: false
    
  4. Reflect.deleteProperty(target, propertyKey)

    • 作用: 删除对象的属性。
    • 示例:
    const obj = { name: 'Frank', age: 40 };
    console.log(Reflect.deleteProperty(obj, 'age'));  // 输出: true
    console.log(obj.age);                             // 输出: undefined
    console.log(Reflect.deleteProperty(obj, 'city')); // 输出: true (删除不存在的属性也会返回 true)
    
  5. Reflect.construct(target, argumentsList[, newTarget])

    • 作用: 类似于使用 new 操作符调用构造函数。
    • 示例:
    class Person {constructor(name, age) {this.name = name;this.age = age;}greeting() {console.log(`Hello, ${this.name}!`);}
    }const args = ['Grace', 30];
    const person1 = Reflect.construct(Person, args);
    person1.greeting() // 输出: Hello, Grace!
    console.log(person1 instanceof Person);        // 输出: true// 使用 newTarget 模拟继承
    class Student extends Person {}
    const student = Reflect.construct(Person, args, Student);
    console.log(student instanceof Student) // 输出 true
    console.log(student instanceof Person) // 输出 true
    
  6. Reflect.getPrototypeOf(target)

    • 作用: 获取对象的原型。
    • 示例:
    const obj = { name: 'Henry' };
    const protoObj = { city : 'Paris' };
    Object.setPrototypeOf(obj, protoObj);
    console.log(Reflect.getPrototypeOf(obj) === protoObj); // 输出: true
    console.log(Reflect.getPrototypeOf(obj) === Object.prototype); // 输出 false
    
  7. Reflect.setPrototypeOf(target, prototype)

    • 作用: 设置对象的原型。
    • 示例:
    const obj = { name: 'Ivy' };
    const newProto = { city : 'Rome' };console.log(Reflect.setPrototypeOf(obj, newProto));    // 输出: true
    console.log(Reflect.getPrototypeOf(obj) === newProto); // 输出: true
    
  8. Reflect.apply(target, thisArgument, argumentsList)

    • 作用: 类似于使用 Function.prototype.apply() 调用函数。
    • 示例:
    function greet(greeting, punctuation) {return `${greeting}, ${this.name}${punctuation}`;
    }const obj = { name: 'Jack' };
    const args = ['Hello', '!'];
    const result = Reflect.apply(greet, obj, args);
    console.log(result);   // 输出: Hello, Jack!
    
  9. Reflect.defineProperty(target, propertyKey, attributes)

    • 作用: 类似于 Object.defineProperty(),用于定义对象的属性。
    • 示例:
    const obj = {};
    const attributes = {value: 'Katy',writable: true,enumerable: true,configurable: true,
    };Reflect.defineProperty(obj, 'name', attributes);
    console.log(obj.name);         // 输出: Katy// 尝试修改值
    obj.name = 'Lily';
    console.log(obj.name);         // 输出: Lily
    
  10. Reflect.ownKeys(target)

    • 作用: 获取对象的所有自身属性的键名,包括 Symbol 类型的键名。
    • 示例:
    const obj = { name: 'Mike', age: 35, [Symbol('symbolKey')]: 'symbolValue'};
    const keys = Reflect.ownKeys(obj);
    console.log(keys);   // 输出: ['name', 'age', Symbol(symbolKey)]
    
  11. Reflect.isExtensible(target)

    • 作用: 判断对象是否可扩展
    • 示例:
    const obj = {name : "Nancy"}
    console.log(Reflect.isExtensible(obj)) // 输出 true
    Reflect.preventExtensions(obj);
    console.log(Reflect.isExtensible(obj)) // 输出 false
    
  12. Reflect.preventExtensions(target)

    • 作用: 让对象不可扩展
    • 示例:
      const obj = {name : "Oliver"}console.log(Reflect.preventExtensions(obj)) // 输出 trueobj.age = 30; // 设置属性无效console.log(obj.age); // 输出 undefined
    

总结:

Reflect 对象提供了一套统一且规范的 API 来操作对象,它的方法通常与 Proxy 对象配合使用,可以实现更加强大和灵活的元编程。

http://www.yayakq.cn/news/782430/

相关文章:

  • 房地产 网站 案例游戏平台网站的建设规划
  • 小型网站开发教程广告制作合同范本
  • 自己注册公司网站公司建网站多
  • 长安做网站网站建设与网页设计论述题
  • 英文网站支付怎么做我的营业执照网上查询
  • 英文网站正在建设页面中文商城html网站模板
  • google的网站优化工具企业公司做网站
  • 宁波企业网站排名优化公司淘宝网站建设杭州
  • 网站推广方法主要有邢台做网站推广费用
  • 松江附近做网站淘宝内部领优惠券的网站怎么建设
  • 网站建设的开题报告商丘网站建设哪家好
  • 网站开发方式有查淘宝关键词排名软件有哪些
  • 作品集模板网站php网站开发预算文档
  • 网站开发 方案 报价单打开网站显示建设中
  • 网站建设制作过程html5游戏WordPress
  • 英文旅游网站建设求职找工作
  • 重庆免费注册推广网站激光网站建设
  • 简述创建一个网站的过程网站地市频道建设
  • 辽宁平台网站建设平台云典 wordpress
  • 代刷网站是怎么做的WordPress下如何用页面做侧边栏
  • 长沙推广网站去除wordpress概览
  • 四川网站设计成功柚米科技wordpress技术站主题
  • 网站admin目录名怎么改html5国内网站
  • 广州网站建设V芯ee8888e廊坊百度提升优化
  • 有没有专门做印刷图的网站抖音推广项目计划书
  • 电子商务网站建设体会与收获学室内装修设计需要什么条件
  • 做货源网站可以赚钱吗建设企业网站官方登录
  • 栾城区住房建设局官方网站用python写一个简单的网站
  • 安徽网站建设做网站怎么申请百度推广
  • .net搭建企业网站牛商网网站建设多少钱