<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
function add(a,b){
return Number(a) + Number(b);
};
var arr = [1,2,3,4,5,6,7,8,9,10];
Array.prototype.reduce_self = function(f,value){
var i; for(i = 0; i<this.length; i+=1){
value = f( this[i] , value )
};
return value;
}; Array.prototype.dim = function(n,init){
var a = [] , i;
for(i = 0; i < n; i+=1){
a[i] = init
};
return a;
}; Array.prototype.matrix = function(m,n,initial){
var a, i, j, mat = [];
for(i=0; i<m; i+=1){
a = [];
for(j=0; j<n; j++){
a[j] = initial;
};
mat[i] = a;
}
return mat;
}; //RegExp
var parse_url = /^(?:([a-zA-z]+):)?(\/{0,3})([0-9.\-a-zA-Z]+)(?::(\d+))?/;
var url = "http://www.chenqihao.com:80/goodparts?q#fragment";
var result = parse_url.exec(url); var names = ['url','scheme','slash','host','port'];
var blanks = ' ', i ;
for(i=0; i<names.length; i+=1){
document.writeln(names[i] + ':' + result[i] + '<br>')
}; //排序
var arr = [2,1,3,66,10,200,28,29];
arr.sort();
console.log(arr)
arr.sort(function(a,b){
if(a<b){
return 1
}else{
return -1
}
});
console.log(arr); var arr1 = [10,29,'ddd',100,'bbd',29,0,18,'a',18,'b'];
arr1.sort(function(a,b){
if( a === b){
return 0;
}
if( typeof a == 'number' && typeof b == 'number' ){
if(a < b){return -1}else{ return 1};
};
if( typeof a < typeof b){
return -1
};
}); var by = function(name){
return function(a,b){
var c,d;
if(typeof a === 'object' && typeof b === 'object' && a && b){
c = a [name],d = b[name];
if(a === b){
return 0
};
if( typeof a === typeof b ){
return a < b ? -1 : 1;
};
return typeof a < typeof b ? -1 : 1;
};
};
};
var obj = [
{f : 'C'},
{f : 'E'},
{f : 'B'},
{f : 'A'},
{f : 'S'}
];
obj.sort( by('f') );
console.log( JSON.stringify(obj) ); var arr = ['a','b','c','d'];
arr._unshift = function(){
this.splice.apply(this,[0,0].concat(Array.prototype.slice.call(arguments)))
};
//Array.prototype.slice.call(arguments) 可以将类数组转换为真数组 Function.prototype._bind = function(that){
var method = this,
slice = Array.prototype.slice,
args = slice.apply(arguments,[1]);
return function(){
method.apply( that,args.concat(slice.apply(arguments,[0])) )
};
}; //下面这个东东,经常服务器返回东西经过编码了,用这个在转下;反正转来转去的
/* 主要是这四个字符 < > & " */
String.prototype.entityfy = function(){
var charactor = {
'<' : '&lt;',
'>' : '&gt;',
'&' : '&amp;',
'"' : '&quot;'
};
var _this = this;
return (function(){
return _this.replace(/[<>&"]/g,function(a){
return charactor[a]
})
})();
};
console.log( '<>&"'.entityfy() )
</script>
</body>
</html>

keep_on _coding——js_good_parts的更多相关文章

  1. 使用etree.HTML的编码问题

    title: 使用etree.HTML的编码问题 date: 2015-10-07 17:56:47 categories: [Python] tags: [Python, lxml, Xpath] ...

  2. Django

    一.Django 简介 Django 是一个由 Python 写成的开放源代码的 Web 应用框架.它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是 CMS(内容管理系统) ...

  3. 21-Python-Django进阶补充篇

    1. 路由部分补充 1.1 默认值 url: url(r'^index/', views.index, {'name': 'root'}), views: def index(request,name ...

  4. Python小白的发展之路之Python基础(一)

    Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...

  5. Django ORM、一对一、一对多、多对多、详解

    上篇博客也提到这些知识点,可能大家还是不太清楚,这篇博客为大家详细讲解ORM中的几个知识点 1.1首先我们先看一个小案例: #_*_coding:utf-8_*_ from django.db imp ...

  6. 冰冻三尺非一日之寒--web框架Django(翻页、cookie)

    第二十一章 cookie 1.获取Cookie: request.COOKIES['key'] request.get_signed_cookie(key, default=RAISE_ERROR, ...

  7. Day5-python基础之函数(二)

    生成器 迭代器 装饰器 模块   来个需求,一个列表中所有元素都+1 1.最容易想到的方法 for循环,找列表索引,对应每个值+1 list_old = [1,2,3,4,5,6,7,8,9] for ...

  8. Python Day21

    Cookie 1.获取Cookie: request.COOKIES['key'] request.get_signed_cookie(key, default=RAISE_ERROR, salt=' ...

  9. Python Day20

    Django 表操作 1.基本操作 # 增 # # models.Tb1.objects.create(c1='xx', c2='oo') 增加一条数据,可以接受字典类型数据 **kwargs # o ...

随机推荐

  1. (新人的第一篇博客)树状数组中lowbit(i)=i&(-i) 的简单文字证明

    第一次写博好激动o(≧v≦)o~~初一狗语无伦次还请多多指教   先了解树状数组http://blog.csdn.net/int64ago/article/details/7429868感觉这个前辈写 ...

  2. testng环境设置

    1.在eclipse中安装testng插件,地址:http://beust.com/eclipse 2.设置testng环境变量 testng_home D:\Program Files\eclips ...

  3. codeforces 709E E. Centroids(树形dp)

    题目链接: E. Centroids time limit per test 4 seconds memory limit per test 512 megabytes input standard ...

  4. python-可变迭代对象在for循环中的风险Risk in FOR loop while looping mutable iterable object

    >>> a = [1,2,3,4,5,6] >>> for item in a: ... a.remove(item) ... >>> a [2, ...

  5. FZU1894 志愿者选拔 --单调队列

    做法:维护一个单调递减序列,只需输出序列中的第一个元素即可. 对于命令我们可以进行不同的处理: 如果是Q命令,则判断当前队列中是否仍有元素,如果没有则输出-1,如果有则直接输出队首. 如果是G命令,则 ...

  6. git rebase 介绍

    git rebase是对commit history的改写.当你要改写的commit history还没有被提交到远程repo的时候,也就是说,还没有与他人共享之前,commit history是你私 ...

  7. java9-9 匿名内部类

    1. 匿名内部类 就是内部类的简化写法. 前提:存在一个类或者接口 这里的类可以是具体类也可以是抽象类. 格式: new 类名或者接口名(){ 重写方法; } new Xxx()是创建了一个对象,而抽 ...

  8. 后台首页品字形(frameset)框架搭建

    get_defined_constants([true])//显示所有常量信息.参数true,表示分组显示,查看当前系统给我提供了哪些常量可以使用,包括自定义常量. __CONTROLLER__//获 ...

  9. iOS请求服务器数据去空NSNull

    我们在处理数据库接口的过程中,如果数据中出现null,我们是没法处理的.我在使用NSUserDaults保存后,出现崩溃. null产生原因 null是后台在处理数据的时候,如果没有设置value值, ...

  10. ralitive absolute

    3.relative与absolute的主要区别: 首先,是上面已经提到过的在正常流中的位置存在与否. 其次,relative定位的层总是相对于其最近的父元素,无论其父元素是何种定位方式.如图3: 图 ...