Skip to content

Instantly share code, notes, and snippets.

@chengyuhui
Created February 13, 2013 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chengyuhui/4945075 to your computer and use it in GitHub Desktop.
Save chengyuhui/4945075 to your computer and use it in GitHub Desktop.
var sm=function(s){
if(typeof s !='object'||s==null)var s=[];
if(typeof s.length =='undefined')s=[s];
return {
segments:s,
addText:function(text){
this.segments.push({
text:text,
type:'TEXT'
});
},
addMention:function(name,id){
this.segments.push({
text:'+'+name,
type:'USER_MENTION',
user:{
name:name,
userId:id
}
});
},
pop:function(time){
if(typeof time =='undefined')var time=1
if(isNaN(parseInt(time)))time=1;
var i=0;
while(i<time){
this.segments.pop();
i++;
}
}
};
};
module.exports=sm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment