- function foo() {
- bar.apply(null, arguments);
- }
- function bar(){
- console.log(arguments);
- }
- foo(1,2,3,4,5);
结果:(1,2,3,4,5)
2,alert 的结果
- function b(x, y, a){
- arguments[2] = 10;
- alert(a);
- }
- b(1, 2, 3);
结果: 10
- 3,typeof f
- var f = (
- function f(){
- return "1";
- },
- function g(){
- return 2;
- }
- )();
- typeof f;
结果;"number"
逗号运算符:(x,y), 输入结果是: 两个值进行比较, 谁大输出谁
- 4,x
- var x = 1;
- if (function f(){}) {
- x += typeof f;
- }
- console.log(x);
结果:"1undefined"
5, 求 100 的阶乘
- var num = (function(n){
- if (n == 1){
- return 1;
- }
- return n * arguments.callee(n-1);
- }(100))
- 6,this
- var foo = '123';
- function print(){
- var foo = '456';
- this.foo = '789';
- console.log(foo);
- }
- print();
结果: 456
- var foo = '123';
- function print(){
- this.foo = '789';
- console.log(foo);
- }
- print();
结果: 789
- var foo = '123';
- function print(){
- this.foo = '789';
- console.log(foo);
- }
- new print();
结果: 123
- 7,print()()
- var bar = {a: "002"};
- function print(){
- bar.a = 'a';
- Object.prototype.b = 'b';
- return function inner() {
- console.log(bar.a);
- console.log(bar.b);
- }
- }
- print()();
结果: a
b
来源: http://www.bubuko.com/infodetail-3071218.html