js中Object.defineProperties 定义一个在原对象可读可写的方法
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 定义一个在原对象可读可写的方法的更多相关文章
- 分享一个Object.defineProperties 定义一个在原对象可读可写的方法
function A(){ this.name = 'hellow word'; } Object.defineProperties( A.prototype,{ doSomething2 : { v ...
- js中Object.defineProperty()和defineProperties()
在介绍js中Object.defineProperty()和defineProperties()之前,我们了解下js中对象两种属性的类型:数据属性和访问器属性. 数据属性 数据属性包含一个数据的位置, ...
- js 中object对象的操作
n = object对象 for(var p in n){ console.log(p);// 取得是key值 console.log(n[p]);//取得是value值 } 继之前js中数组的常用方 ...
- JS中,如何判断一个被转换的数是否是NaN
var x="abc"; //isNaN()函数判断是否是NaN if (isNaN(parseInt(x))) { alert("非数字"); } else{ ...
- js中三种定义变量 const, var, let 的区别
js中三种定义变量的方式const, var, let的区别 1.const定义的变量不可以修改,而且必须初始化. 1 const b = 2;//正确 2 // const b;//错误,必须初始化 ...
- js中object、字符串与正则表达式的方法
对象 1.object.hasOwnProperty(name) 检测object是否包含一个名为name的属性,那么hasOwnProperty方法返回true,但是不包括其原型上的属性. 正则表达 ...
- using 中写 return 一样会释放using 中对象 但是会在外面定义一个一样的对象 赋值后 释放 最后 return 外面定义的那个对象
static DataTable getDataTable() { ")) { SqlCommand com = new SqlCommand("", con); Sql ...
- js中使用function定义类、实例化,函数的调用方法
function Test002(name, age){ name, age, this.printInfo = function(){ //定义的公有方法 console.log(name, age ...
- 定义一个Rectangle类,该类提供getLength和getWidth方法。
import java.util.Comparator; /** * 定义一个Rectangle类,该类提供getLength和getWidth方法.利用图1-18中的findMax例程编写 * 一种 ...
随机推荐
- ListView有Header时的position情况
问题: headerView 为第0个view,item 的 pos会从1开始. 解决方式: position减去 listView.getHeaderViewsCount().例如我想得到list ...
- Python dataframe中如何使y列按x列进行统计?
如图:busy=0 or 1,求出busy=1时los的平均,同样对busy=0时也求出los的平均 Python dataframe中如何使y列按x列进行统计? >> python这个答 ...
- python import windows文件路经
import sys sys.path.append("E:\\python\\workspacepython\\PY001\\src\\testpy01") import str ...
- SPOJ8222 NSUBSTR - Substrings 后缀自动机_动态规划
讲起来不是特别好讲.总之,如果 $dp[i+1]>=dp[i]$,故$dp[i]=max(dp[i],dp[i+1])$ Code: #include <cstdio> #inclu ...
- Java Web Application——servlet
概述 是一个部署于web服务器中的实现了servlet接口的Java类,用于响应web请求 Web容器(也称为servlet容器)本质上是与servlet交互的Web服务器的组件.Web容器负责管理s ...
- 【CS Round #36 (Div. 2 only) A】Bicycle Rental
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
- Consolas 字体
Consolas是一套等宽字体的字型,属无衬线字体,由Lucas de Groot设计. 概述 这套字型使用了微软的ClearType 字型平滑技术,并随同Windows Vista.Office 2 ...
- mysql二进制日志文件出错导致mysql服务无法启动
今天打开phpmyadmin发现连不上mysql数据库,重新启动mysql启动不起来,查看日志发现例如以下错误 <span style="font-family:SimSun;font ...
- netsh http的使用
1.首先通过cmd进入 C:\Windows\System32\inetsrv>netshnetsh>http netsh http> 退出的时候,使用exit命令 2.显示监听的i ...
- Gym - 100625E Encoded Coordinates 矩阵快速幂
题意: 一直TLE我也是醉了,,不爽! #include <iostream> #include <cstdio> #include <fstream> #incl ...