function A(){
   this.name = 'hellow word';
}

Object.defineProperties(
  A.prototype,{
  doSomething2 : {
    value: function(parm){
      console.log(parm)
    },
    enumerable: true,
    configurable: true,
    writable: true
  }
})

var a2 = new A()

a2.doSomething2(232);
 

Object.defineProperties(obj,{
  "sex":{
     value:"ajia",
     writable:true,
     enumerable:true,
     configurable:true
   },
   "age":{
      value:26,
      writable:true,
      enumerable:true,
      configurable:true
   },
    "name":{
      value:"ajia",
      writable:true,
      enumerable:true,
      configurable:true
   }
})

//Object.defineProperty()的用法
var _value = null;
var obj = {};
[].forEach.call(str,function(v,i,arr){
   Object.defineProperty(obj,v,{
     get:function(){return _value;},
     set:function(newVal){return _value = newVal;},
     enumerable:true,
     configurable:true
   })
})

js中Object.defineProperties 定义一个在原对象可读可写的方法的更多相关文章

  1. 分享一个Object.defineProperties 定义一个在原对象可读可写的方法

    function A(){ this.name = 'hellow word'; } Object.defineProperties( A.prototype,{ doSomething2 : { v ...

  2. js中Object.defineProperty()和defineProperties()

    在介绍js中Object.defineProperty()和defineProperties()之前,我们了解下js中对象两种属性的类型:数据属性和访问器属性. 数据属性 数据属性包含一个数据的位置, ...

  3. js 中object对象的操作

    n = object对象 for(var p in n){ console.log(p);// 取得是key值 console.log(n[p]);//取得是value值 } 继之前js中数组的常用方 ...

  4. JS中,如何判断一个被转换的数是否是NaN

    var x="abc"; //isNaN()函数判断是否是NaN if (isNaN(parseInt(x))) { alert("非数字"); } else{ ...

  5. js中三种定义变量 const, var, let 的区别

    js中三种定义变量的方式const, var, let的区别 1.const定义的变量不可以修改,而且必须初始化. 1 const b = 2;//正确 2 // const b;//错误,必须初始化 ...

  6. js中object、字符串与正则表达式的方法

    对象 1.object.hasOwnProperty(name) 检测object是否包含一个名为name的属性,那么hasOwnProperty方法返回true,但是不包括其原型上的属性. 正则表达 ...

  7. using 中写 return 一样会释放using 中对象 但是会在外面定义一个一样的对象 赋值后 释放 最后 return 外面定义的那个对象

    static DataTable getDataTable() { ")) { SqlCommand com = new SqlCommand("", con); Sql ...

  8. js中使用function定义类、实例化,函数的调用方法

    function Test002(name, age){ name, age, this.printInfo = function(){ //定义的公有方法 console.log(name, age ...

  9. 定义一个Rectangle类,该类提供getLength和getWidth方法。

    import java.util.Comparator; /** * 定义一个Rectangle类,该类提供getLength和getWidth方法.利用图1-18中的findMax例程编写 * 一种 ...

随机推荐

  1. vue.js技巧小计

    //删除数组索引方法01 del (index) { this.arr.splice(index ,1); } //删除数组索引方法01 del (index) { this.$delete(this ...

  2. HDU 4324 Triangle LOVE【拓扑排序】

    题意:给出n个人,如果a喜欢b,那么b一定不喜欢a,如果b不喜欢a,那么a一定喜欢b 就是这n个点里面的任意两点都存在一条单向的边, 所以如果这n个点不能构成拓扑序列的话,就一定成环了,成环的话就一定 ...

  3. AIX 6.1 Oracle 10G 数据库GoldenGate实施

    安装环境说明: 源端:AIX 6.1 10.190.1.215 目标端:Linux 10.191.1.10 1:源端创建goldengate 表空间. 表空间的要求:最小500m,大点3-5G,设置自 ...

  4. Linux系统启动U盘制作工具

    1.UNetbootin UNetbootin 让你创建 Ubuntu 或者其他 Linux 发行版的可引导 Live U 盘,而无需烧录 CD. 你既能让 UNetbootin 为你下载众多开箱即用 ...

  5. 三维偏序(陌上花开) CDQ分治

    十分巧妙. Code: #include <cstdio> #include <algorithm> #include <cstring> #define setI ...

  6. JavaScript设计模式(biaoyansu)

    1.构造器模式——创建类模式   ES6:class Student{ constructor(score,quality){ this.score = score this.quality = qu ...

  7. 洛谷P1280 && caioj 1085 动态规划入门(非常规DP9:尼克的任务)

    这道题我一直按照往常的思路想 f[i]为前i个任务的最大空暇时间 然后想不出来怎么做-- 后来看了题解 发现这里设的状态是时间,不是任务 自己思维还是太局限了,题做得太少. 很多网上题解都反着做,那么 ...

  8. unity C# 获取有关文件、文件夹和驱动器的信息

    class FileSysInfo { static void Main() { // You can also use System.Environment.GetLogicalDrives to ...

  9. What is x86 Conforming Code Segment?

    SRC=Microprocessor Based Systems SRC=Computer Architecture: A Quantitative Approach

  10. Watcher详解 工作机制, Watcher客户端注册、Watcher 服务端注册

    Watcher详解.接口 在 ZooKeeper 中, 接口类 Watcher 用于表示一个标注你的事件处理器,其定义了事件通知相关的逻辑,包含 KeeperState 和 EventType 两个枚 ...