Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function testArguments () // <-- notice no arguments specified
- {
- console.log(arguments); // outputs the arguments to the console
- var htmlOutput = "";
- for (var i=0; i < arguments.length; i++) {
- htmlOutput += '<li>' + arguments[i] + '</li>';
- }
- document.write('<ul>' + htmlOutput + '</ul>');
- }
- testArguments("This", "is", "a", "test"); // outputs ["This","is","a","test"]
- testArguments(1,2,3,4,5,6,7,8,9); // outputs [1,2,3,4,5,6,7,8,9]
- argumentsArray = [].slice.apply(arguments);
- function ArgumentsToArray(args) {
- return [].slice.apply(args);
- }
- (function() {
- args = ArgumentsToArray(arguments);
- args.forEach(function(value) {
- console.log('value ===', value);
- });
- })('name', 1, {}, 'two', 3)
- function foo()
- {
- foo.bar = JSON.stringify(arguments);
- foo.baz = JSON.parse(foo.bar);
- }
- /* Atomic Data */
- foo(1,2,3,4,5,6,7);
- foo.bar // "{"0":1,"1":2,"2":3,"3":4,"4":5,"5":6,"6":7}"
- foo.baz // [object Object]
- /* Structured Data */
- foo({1:2},[3,4],/5,6/,Date())
- foo.bar //"{"0":{"1":2},"1":[3,4],"2":{},"3":"Tue Dec 17 2013 16:25:44 GMT-0800 (Pacific Standard Time)"}"
- foo.baz // [object Object]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement