Article Introduction: javascript face test. |
Requirements:
1, only in the designated location to fill out their own code, the other code in this document can not be modified
2, all topics are not allowed to add global variable name
3, this document should be able to operate in the Firebug console, and output results
4, the code optimization, the highest efficiency
5. Clear code Annotation
Exercise 1:
Implements an iterator that iterates through an array or all members of an object.
var each = function (obj, fn) {
+++++++++++ Answer Area +++++++++++
+++++++++++ the end of the answer +++++++++++
};
try{
var data1 = [4,5,6,7,8,9,10,11,12];
var data2 = {
"A": 4,
"B": 5,
"C": 6
};
Console.group (DATA1);
Each (data1, function (o) {
if (6 = = this)
return true;
else if (8 = this)
return false;
Console.log (o + ": \" "+ This +" \ ");
});
Console.groupend ();
/*------[Execution Results]------
1: "4"
2: "5 "
4:" 7 "
------------------*/
console.group (data2);
&NBSP
Each (data2, function (V, n) {
if (5 = = this)
return true;
Console.log (n + ": \" "+ V +" \ ");
});
Console.groupend ();
/*------[Execution Results]------
A: "4"
C: "6"
------------------*/
}catch (e) {
Console.error ("Execution error, error message:" + E);
}
Exercise 2:
Implement a class called Man, including attr, words, say three methods.
var Mans;
+++++++++++ Answer Area +++++++++++
+++++++++++ the end of the answer +++++++++++
try{
var me = man ({fullname: "Little Red"});
var she = new Man ({fullname: "Little Red"});
Console.group ();
Console.info ("My name is:" + me.attr ("fullname") + "\ n My gender is:" + me.attr ("gender"));
Console.groupend ();
/*------[Execution Results]------
My name is: Xiao Hong
My sex is:<. User not entered >
------------------*/
Me.attr ("FullName", "xiaoming");
Me.attr ("Gender", "male");
Me.fullname = "Waste firewood";
Me.gender = "Simon";
She.attr ("Gender", "female");
Console.group ();
Console.info ("My name is:" + me.attr ("fullname") + "\ n My gender is:" + me.attr ("gender"));
Console.groupend ();
/*------[Execution Results]------
My name is: Xiao Ming
My gender is: male
------------------*/
Console.group ();
Console.info ("My name is:" + she.attr ("fullname") + "\ n My gender is:" + she.attr ("gender"));
Console.groupend ();
/*------[Execution Results]------
My name is: Xiao Hong
My gender is: female
------------------*/
me.attr ({
"Words-limit": 3,
"Words-emote": "Smile"
});
me.words ("I like watching videos.") ");
me.words ("Our office is so beautiful.") ");
me.words ("There are so many beauties in the video!") ");
me.words ("I usually see Youku!") ");
Console.group ();
console.log (Me.say ());
&NBSP
/*------[Execution Results]------
&NBSP
Xiao Ming smiled: "I like watching video." Our office is so beautiful. There are so many beauties in the video! "
------------------*/
Me.attr ({
"Words-limit": 2,
"Words-emote": "Shout"
});
Console.log (Me.say ());
Console.groupend ();
/*------[Execution Results]------
Xiao Ming shouted: "I like watching video." Our office is so beautiful. "
------------------*/
}catch (e) {
Console.error ("Execution error, error message:" + E);
}
Exercise 3:
Implements a URI parsing method that parses the parameters after the # in the URL into the specified data structure.
function Urlparser (s) {
+++++++++++ Answer Area +++++++++++
+++++++++++ the end of the answer +++++++++++
}
try{
var url1 = "http://www.abc.com/m/s/";
var url2 = "http://www.abc.com/m/s/";
var url3 = "http://www.abc.com/m/s/";
Console.group ();
Console.info (Urlparser (URL1));
Console.info (Urlparser (URL2));
Console.info (Urlparser (URL3));
Console.groupend ();
/*------[Execution Results]------
["Page", "2", {"type": "Latest_videos", "Page_size": 20}]
[{' type ': ' Latest_videos ', ' page_size ': 20}]
[' page ', {' type ': ' Latest_videos ', ' page_size ': 20}]
------------------*/
}catch (e) {
Console.error ("Execution error, error message:" + E);
}