function showStatistics(args) {
document.write("<p><strong>Name:</strong> " + args.name + "<br />");
document.write("<strong>Team:</strong> " + args.team + "<br />");
if (typeof args.position === "string") {
document.write("<strong>Position:</strong> " + args.position + "<br />");
}
if (typeof args.average === "number") {
document.write("<strong>Average:</strong> " + args.average + "<br />");
}
if (typeof args.homeruns === "number") {
document.write("<strong>Home Runs:</strong> " + args.homeruns + "<br />");
}
if (typeof args.rbi === "number") {
document.write("<strong>Runs Batted In:</strong> " + args.rbi + "</p>");
}
}
showStatistics({
name: "Mark Teixeira"
});
showStatistics({
name: "Mark Teixeira",
team: "New York Yankees"
});
showStatistics({
name: "Mark Teixeira",
team: "New York Yankees",
position: "1st Base",
average: .284,
homeruns: 32,
rbi: 101
});
6 Advanced JavaScript Techniques You Should Know - 3 views
-
-
Object-oriented JavaScript implements namespace-like principles due to the fact that properties and methods are declared inside of objects, thus there are less likely to be conflicts. A conflict could arise, however, through object names. And very likely, the conflict will occur "silently", thus you may not be alerted to the issue immediately.
-
if (typeof MY == "undefined") { MY = new Object(); MY.CUSTOM = new Object(); } MY.CUSTOM.namespace = function() { function showStatistics(args) { document.write("<p><strong>Name:</strong> " + args.name + "<br />"); document.write("<strong>Team:</strong> " + args.team + "<br />"); if (typeof args.position === "string") { document.write("<strong>Position:</strong> " + args.position + "<br />"); } if (typeof args.average === "number") { document.write("<strong>Average:</strong> " + args.average + "<br />"); } if (typeof args.homeruns === "number") { document.write("<strong>Home Runs:</strong> " + args.homeruns + "<br />"); } if (typeof args.rbi === "number") { document.write("<strong>Runs Batted In:</strong> " + args.rbi + "</p>"); } } showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 }); } MY.CUSTOM.namespace();
- ...1 more annotation...
-
//2. Object Literals to Pass Optional Arguments function showStatistics(args) { document.write("Name: " + args.name + "
"); document.write("Team: " + args.team + "
"); if (typeof args.position === "string") { document.write("Position: " + args.position + "
"); } if (typeof args.average === "number") { document.write("Average: " + args.average + "
"); } if (typeof args.homeruns === "number") { document.write("Home Runs: " + args.homeruns + "
"); } if (typeof args.rbi === "number") { document.write("Runs Batted In: " + args.rbi + ""); } } showStatistics({ name: "Mark Teixeira" }); showStatistics({ name: "Mark Teixeira", team: "New York Yankees" }); showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 }); //Using Namespaces to Prevent Conflicts if (typeof MY == "undefined") { MY = new Object(); MY.CUSTOM = new Object(); } MY.CUSTOM.namespace = function() { function showStatistics(args) { .................. } showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 }); } MY.CUSTOM.namespace();
JavaScript: The World's Most Misunderstood Programming Language - 1 views
-
JavaScript: The World's Most Misunderstood Programming Language
-
This is misleading because JavaScript has more in common with functional languages like Lisp or Scheme than with C or Java.
-
It has arrays instead of lists and objects instead of property lists. Functions are first class. It has closures. You get lambdas without having to balance all those parens.
- ...1 more annotation...
Playing with JQuery Validation Library, Part 2 | Elegant Code - 2 views
-
The new part is the remote in the script. You give it the name/location of your web service to call to validate the field, and the field name/value are passed in.
-
1: $('#UserNameForm').validate({ 2: rules: { 3: userNameEdit: { required: true, remote: "<%=Url.Action("VerifyUserName", "Account") %>" } 4: } 5: });
50个必备的实用jQuery代码段_HTML5研究小组_HTML5教程_HTML5资源_HTML5游戏 - 0 views
-
var $events = $("#foo").data("events"); if( $events && $events["click"] ){ //your code }
Asset Management : Combining multiple JS files and minify - Server Side Coding (eg: PHP... - 0 views
« First
‹ Previous
81 - 88 of 88
Showing 20▼ items per page