Skip to content
Snippets Groups Projects
Commit 0e5393f5 authored by deuce's avatar deuce
Browse files

Add an example usage of prototypes...

When this code is load()ed, User objects get an extra birthDate property
which is a JavaScript Date object representing the birthdate (rather than
a string).

This adds the property to existing instances as well, so it doesn't need to
be loaded early.
parent c74264d9
No related branches found
No related tags found
No related merge requests found
/*
* When this code is load()ed, User objects get an extra borthDate propert
* which is a JavaScript Date object representing the birthdate.
*/
User.prototype.birthDate getter=function() {
var mfirst=system.datestr(1728000).substr(0,2)=='01';
var match;
var m,d,y;
match=this.birthdate.match(/^([0-9]{2})[-/]([0-9]{2})[-/]([0-9]{2})$/);
if(match==null)
return undefined;
m=parseInt(match[mfirst?1:2],10)-1;
d=parseInt(match[mfirst?2:1],10);
y=parseInt(match[3],10)+1900;
if(this.age + y < (new Date()).getYear()-2)
y+=100;
return new Date(y,m,d);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment