var test = (function(){ var self = {}; self.alert = function(){ console.log('this is alert') } //sleep self.sleep = function(){}, self.extendJson = function(){}, self.formatParams = function(){}, self.httpAgent = function(){}, self.randomChar = function(){}, self.getCharLen = function(){}, self.subStr = function(){}, self.getPara = function(){}, self.subTime = function(){},//计算时间差,返回毫秒数 self.getUnixTime = function(){},//获取unix时间 self.formatTime = function(){},//时间格式化 self.getCookie = function(){},//获取cookie self.setCookie = function(){},//设置cookis self.getMeta = function(key){//获取meta标签内容 return document.querySelector('meta[name="'+key+']').getAttribute('content'); }, self.setMeta = function(key,des){//设置meta内容 document.querySelector('meta[name="'+key+']').setAttribute('content','des'); }, self.setMetaKey = function(des){ document.querySelector('meta[name="keywords"]').setAttribute('content',des.replace(/"/g,'”')); }, self.setMetaDes = function(des){ document.querySelector('meta[name="description"]').setAttribute('content',des.replace(/"/g,'”')); }, self.setSeo = function(title,keywords,des){ document.title = title+'-'+document.title; self.setMetaKey(keywords); self.setMetaDes(des); } return self; }())