JavaScript笔记-方法
https://www.liaoxuefeng.com/wiki/1022910821149312基于廖雪峰老师的教程所做的笔记。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>方法的操作展示</title> </head> <body>
<script>
var obj={ name:"Sang", age:20, show:function(){ console.log(this.name,this.age); } } obj.show();
var student={ name:"Sang", school:"Hainan University", show:function(){ var that=this; function showName() { console.log(that.name); } showName(); console.log(this.school); } } student.show();
var tell=function () { console.log(this.name+", how are you?"); }
tell.apply(student,[]);
var count=0; var oldParseInt=parseInt; window.parseInt=function(){ count+=1; return oldParseInt.apply(null,arguments); } parseInt('10'); parseInt('20'); parseInt('30'); console.log('count=',count); </script> </body> </html>
|