日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

逆推继承看原型 函数的角色 函数声明和函数表达式的区别 函数中this指向的问题

發布時間:2024/4/13 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 逆推继承看原型 函数的角色 函数声明和函数表达式的区别 函数中this指向的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

逆推繼承看原型

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script>function F1(age){this.age = age;}function F2(age){this.age = age;}F2.prototype = new F1(10);function F4(age){this.age = age;}F4.prototype = new F2(20);var f4 = new F4(40);console.log(f4.age);</script> </head> <body></body> </html>

函數的角色

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script>// 函數的角色:// 函數的聲明function f1(){console.log("我是函數");}f1();// 函數表達式var ff = function(){console.log("我也是一個函數");};ff();</script> </head> <body></body> </html>

?

函數聲明和函數表達式的區別

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script>// 函數聲明 // if(true){// function f1(){// console.log("哈哈,我又變帥了");// }// }else{// function f1(){// console.log("小蘇好猥瑣");// }// }// f1();// 函數表達式var ff;if(true){ff = function(){console.log("哈哈,我又變帥了");};}else{ff = function(){console.log("小蘇好猥瑣");};}ff();// 函數聲明如果放在if-else的語句中,在IE8的瀏覽器中會出現問題// 以后寧愿用函數表達式,都不用函數聲明var ff = function(){};</script> </head> <body></body> </html>

函數中this指向的問題

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script>/*** 函數中this的指向* 普通函數中的this是誰?----window* 對象.方法中的this是誰?----當前的實例對象* 定時器方法中的this是誰?----window* 構造函數中的this是誰?----實例對象* 原型對象方法中的this是誰?----實例對象* * */// 嚴格模式:"use strict";function f1(){// windowconsole.log(this);}window.f1();// var obj = {// sayHi:function(){// }// };// 普通函數// function f1(){// console.log(this);// }// f1();// BOM中頂級對象是window,瀏覽器中所有的東西window的// 定時器中的this// setInterval(function(){// console.log(this);// },1000);// function Person(){// // console.log(this);// this.sayHi = function(){// console.log(this);// };// }// Person.prototype.eat = function(){// console.log(this);// };// var per = new Person();// console.log(per);// // per.sayHi();// per.eat();// 普通函數// 構造函數// 對象的方法</script> </head> <body></body> </html>

?

總結

以上是生活随笔為你收集整理的逆推继承看原型 函数的角色 函数声明和函数表达式的区别 函数中this指向的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。