当前位置: 编程技术>WEB前端
本页文章导读:
▪获取处理前URL StringBuffer backUrl = new StringBuffer();
backUrl.append("http://").append(request.getServerName());
if (request.........
▪js去除重复字符串 function filterRepeatStr(str){var ar2 = str.split(",");var array = new Array();var j=0for(var i=0;i<ar2.length;i++){ if((array == "" || array.toString().match(new RegExp(ar2[i],"g")) == null)&&ar2[i]!=""){ array[j] =ar2[i];.........
▪Javascript 继承模式 在面向对象的JavaScript开发中使用继承可以提高代码重用性,javascript有多重方式可以实现继承,考虑代码的可维护性在项目中应该保持代码风格的一致性,下面是JavaScript中继承的实现方式之一.........
[1]获取处理前URL
来源: 互联网 发布时间: 2013-10-22
StringBuffer backUrl = new StringBuffer();
backUrl.append("http://").append(request.getServerName());
if (request.getServerPort() != 80)
{
backUrl.append(":").append(request.getServerPort());
}
backUrl.append(request.getContextPath()).append(request.getServletPath()).append("?").append(
request.getQueryString());
ServletActionContext.getRequest().getSession().setAttribute(WapstoreOnlineConstants.SESSION_WAP_RESURL,
backUrl.toString());
return backUrl.toString();
backUrl.append("http://").append(request.getServerName());
if (request.getServerPort() != 80)
{
backUrl.append(":").append(request.getServerPort());
}
backUrl.append(request.getContextPath()).append(request.getServletPath()).append("?").append(
request.getQueryString());
ServletActionContext.getRequest().getSession().setAttribute(WapstoreOnlineConstants.SESSION_WAP_RESURL,
backUrl.toString());
return backUrl.toString();
作者:zhangweikai966 发表于2013-1-9 15:27:14 原文链接
阅读:0 评论:0 查看评论
[2]js去除重复字符串
function filterRepeatStr(str){
var ar2 = str.split(",");
var array = new Array();
var j=0
for(var i=0;i<ar2.length;i++){
if((array == "" || array.toString().match(new RegExp(ar2[i],"g")) == null)&&ar2[i]!=""){
array[j] =ar2[i];
array.sort();
j++;
}
}
return array.toString();
}
本文链接
[3]Javascript 继承模式
在面向对象的JavaScript开发中使用继承可以提高代码重用性,javascript有多重方式可以实现继承,考虑代码的可维护性在项目中应该保持代码风格的一致性,下面是JavaScript中继承的实现方式之一:
辅助对象:
var global = window;
(function(ns,undefined){
//辅助对象:
var Class = {
extends: function(SubClass, SuperClass){
var F = function() {};
F.prototype = SuperClass.prototype;
SubClass.prototype = new F();
SubClass.prototype.constructor = SubClass;
SubClass.base = SuperClass.prototype;
if(SuperClass.prototype.constructor == Object.prototype.constructor) {
SuperClass.prototype.constructor = SuperClass;
}
}
}
global.Class = Class;
}(global, undefined));
(function(ns,undefined){
//辅助对象:
var Class = {
extends: function(SubClass, SuperClass){
var F = function() {};
F.prototype = SuperClass.prototype;
SubClass.prototype = new F();
SubClass.prototype.constructor = SubClass;
SubClass.base = SuperClass.prototype;
if(SuperClass.prototype.constructor == Object.prototype.constructor) {
SuperClass.prototype.constructor = SuperClass;
}
}
}
global.Class = Class;
}(global, undefined));
继承模式:
function Person(name){
this.name = name;
}
Person.prototype = {
getName: function(){
console.log("Person.prototype.getName")
},
say: function(){
console.log("Person.prototype.say")
}
};
function Employee(title, name){
Employee.base.constructor.call(this, name);
this.title = title;
}
Class.extends(Employee, Person);
//重写person.prototype.say
Employee.prototype.say = function(){
Employee.base.say.call(this);//调用父类方法
console.log("Employee.prototype.say");
};
Employee.prototype.getTitle = function(){
console.log("Employee.prototype.getTitle")
};
this.name = name;
}
Person.prototype = {
getName: function(){
console.log("Person.prototype.getName")
},
say: function(){
console.log("Person.prototype.say")
}
};
function Employee(title, name){
Employee.base.constructor.call(this, name);
this.title = title;
}
Class.extends(Employee, Person);
//重写person.prototype.say
Employee.prototype.say = function(){
Employee.base.say.call(this);//调用父类方法
console.log("Employee.prototype.say");
};
Employee.prototype.getTitle = function(){
console.log("Employee.prototype.getTitle")
};
调用演示:
var e = new Employee("前端", "jser");
console.log(e.name)
console.log(e.title)
e.getName()
e.getTitle()
e.say()
//运行结果:
//jser
//前端
//Person.prototype.getName
//Employee.prototype.getTitle
//Person.prototype.say
//Employee.prototype.say
console.log(e.name)
console.log(e.title)
e.getName()
e.getTitle()
e.say()
//运行结果:
//jser
//前端
//Person.prototype.getName
//Employee.prototype.getTitle
//Person.prototype.say
//Employee.prototype.say
本文链接
最新技术文章: