javascript笔记
2016-04-30 13:43
597 查看
存取器属性:
var o={$n:0,
get n(){return this.$n;},
set n(n){this.$n=n;}
};
o.n=5;
o.n //5;
o.hasOwnProperty("$n"); //true;
o.propertyIsEnumerable("toString"); //false;
Object.getOwnPropertyDescriptor(o,"$n");
Object.defineProperty(o,"$n",{value:7,writable:false,enumerable:true})
Object.prototype.toString.call(p);//判断类型
p instanceof Point;
p.constructor===Point;
typeof p;//will return Object.
Object.preventExtention(o);
Object.isExtensible(o);
function fun(){
arguments.length;实参个数
this.length;//形参个数
}
function Point(x,y){this.x=x;this.y=y;}
Point.prototype.show=function(){console.log(x+y);}
var p=new Point(3,4);
p.constructor===Point //true;
----------------------------------
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype = {
constructor:Point,
show: function () {
console.log(x + y);
}
}
var p = new Point(3, 4);
p.constructor === Point //true;
---------------------------------------
javascript: function enumeration(nameToValues) {
var enumeration = function () {
throw 'can\'t instantiate the instance!'
};
var enumerator = function () {
};
var proto = enumerator.prototype = {
constructor: enumeration,
toString: function () {
return this.name;
},
valueOf: function () {
return this.value;
},
toJson: function () {
return this.name;
}
};
enumeration.values = [
];
for (var name in nameToValues) {
var e = new enumerator;
e.name = name;
e.value = nameToValues[name];
enumeration[name] = e;
enumeration.values.push(e);
}
return enumeration;
}
var Cards = enumeration({
Red: 1,
Green: 2,
Blue: 3
});
Cards['Red']
var o={$n:0,
get n(){return this.$n;},
set n(n){this.$n=n;}
};
o.n=5;
o.n //5;
o.hasOwnProperty("$n"); //true;
o.propertyIsEnumerable("toString"); //false;
Object.getOwnPropertyDescriptor(o,"$n");
Object.defineProperty(o,"$n",{value:7,writable:false,enumerable:true})
Object.prototype.toString.call(p);//判断类型
p instanceof Point;
p.constructor===Point;
typeof p;//will return Object.
Object.preventExtention(o);
Object.isExtensible(o);
function fun(){
arguments.length;实参个数
this.length;//形参个数
}
function Point(x,y){this.x=x;this.y=y;}
Point.prototype.show=function(){console.log(x+y);}
var p=new Point(3,4);
p.constructor===Point //true;
----------------------------------
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype = {
constructor:Point,
show: function () {
console.log(x + y);
}
}
var p = new Point(3, 4);
p.constructor === Point //true;
---------------------------------------
javascript: function enumeration(nameToValues) {
var enumeration = function () {
throw 'can\'t instantiate the instance!'
};
var enumerator = function () {
};
var proto = enumerator.prototype = {
constructor: enumeration,
toString: function () {
return this.name;
},
valueOf: function () {
return this.value;
},
toJson: function () {
return this.name;
}
};
enumeration.values = [
];
for (var name in nameToValues) {
var e = new enumerator;
e.name = name;
e.value = nameToValues[name];
enumeration[name] = e;
enumeration.values.push(e);
}
return enumeration;
}
var Cards = enumeration({
Red: 1,
Green: 2,
Blue: 3
});
Cards['Red']
相关文章推荐
- 【转载】JS监听DOM结构变化
- javascript---学习笔记
- JSON.parse()和JSON.stringify()
- Javascript数组Array的forEach方法
- volley post非json格式数据并获取json数据
- js实现的万能flv网页播放器代码
- js实现的下拉框二级联动效果
- js实现精确到秒的日期选择器完整实例
- js简单倒计时实现代码
- 【JS】IP大小端转换&十进制数字转换成IP
- JavaScript 基础回顾——数组
- JavaScript 基础回顾——函数
- JavaScript 基础回顾——对象
- js中null和undefined的区别
- Js中实现网页上导航条的切换功能
- cojs 西瓜 解题报告
- json详解
- net.sf.json-lib无法加入项目的解决方法
- extjs2下拉树选项框comboxWithTree(支持异步加载子节点)
- bzoj 2208: [Jsoi2010]连通数