Created
January 15, 2014 20:26
-
-
Save draeton/8443879 to your computer and use it in GitHub Desktop.
Processing url parameters...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Parameter = function (name /* , value* */) { | |
this.name = name; | |
this.values = [].slice.call(arguments, 1); | |
}; | |
Parameter.prototype.toString = function () { | |
return this.values.map(function (value) { | |
return this.name + '=' + value; | |
}.bind(this)).join('&'); | |
}; | |
var Search = function (/* parameter* */) { | |
this.parameters = [].slice.call(arguments); | |
}; | |
Search.prototype.toString = function () { | |
return this.parameters.join('&'); | |
}; | |
Search.prototype.toJSON = function () { | |
return this.parameters; | |
}; | |
var p1 = new Parameter('fruit', 'apple', 'banana', 'pear'); | |
var p2 = new Parameter('car', 'camry', 'focus'); | |
var p3 = new Parameter('cat', 'lion'); | |
var search = new Search(p1, p2, p3); | |
console.log(search); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment