test1();
function test1() { //函数声明
alert("1111");
}
test2();
var test2 = function(){ //函数字面量
alert("2222");
}
test3();
var test3 = new Function("alert(3333);"); //运行时,初始化函数体
function f(){return 1;}
console.log(f()); // 第四个函数把第一个函数覆盖
var f = new Function("return 2;");
console.log(f()); // 第二个函数把第四个函数覆盖
var f = function() {return 3;}
console.log(f()); // 第三个函数把第二个函数覆盖
function f(){return 4;}
console.log(f()); // 第四个函数已经被覆盖
var f = new Function("return 5;");
console.log(f()); // 第五个函数把第三个函数覆盖
var f = function(){return 6;}
console.log(f()); // 第六个函数把第五个函数覆盖
var k = 4;
window.onload=function() {
var k=1;
function t1() {
var k = 2;
function test(){return k;}
console.info(test()); // 弹出 2
var test = function(){return k;};
console.info(test()); // 弹出 2
var test = new Function("return k;"); // 每次执行的时候,动态的new,顶级作用域,无法获得局部变量
console.info(test()); // 弹出 4
}
t1();
};
var f = function fact(x) {
if (x < = 1) return 1;
else return x*fact(x-1);
};
var y = “global”;
function constructFunction() {
var y = “local”;
return new Function(“return y”); // 无法获取局部变量 }
alert(constructFunction()()); // 输出 “global”
var a = 10 + function(){
return 5;
}();
(function(){
alert(1);
} ) ( );
( function(){
alert(2);
} ( ) );
void function(){
alert(3);
}()
0, function(){
alert(4);
}();
-function(){
alert(5);
}();
+function(){
alert(6);
}();
!function(){
alert(7);
}();
~function(){
alert(8);
}();
typeof function(){
alert(9);
}();
//方式一,调用函数,得到返回值。强制运算符使函数调用执行
(function(x,y){
alert(x+y);
return x+y;
}(3,4));
//方式二,调用函数,得到返回值。强制函数直接量执行再返回一个引用,引用在去调用执行
(function(x,y){
alert(x+y);
return x+y;
})(3,4);
//方式三,调用函数,忽略返回值
void function(x) {
x = x-1;
alert(x);
}(9);
//错误的调用方式
function(x,y){
alert(x+y);
return x+y;
}(3,4);
var obj=new Object(); obj.x=new Array(1,2); obj.y=23;
(function(){
document.write(“some script code”);
})()
var a=(function(s){return s})(“abc”);
alert(a);
var b=function(s){return s};
alert(b(“abc”));
var blogInfo={
blogId:123,
blogName:"werwr",
showBlog:function(){alert(this.blogId);}
};
blogInfo.showBlog();
var myfunc = function(a,b){
return a+b;
}
alert(myfunc(3,4));
var myfunc = function(a){
this.a = a;
};
myfunc.prototype = {
show:function(){alert(this.a);}
}
var newfunc = new myfunc("123123123");
newfunc.show();
var myobject={};
var sum = function(a,b){
return a+b;
};
var sum2 = sum.call(myobject,10,30); //var sum2 = sum.apply(myobject,[10,30]);
alert(sum2);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有