给Object扩展新方法
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>关于hasOwnProperty()方法的应用</title> 6 </head> 7 <body> 8 <script> 9 if (typeof Object.prototype.clone === "undefined") { 10 Object.prototype.clone = function () { 11 alert(this.b) 12 }; 13 } 14 var a ={b:1} 15 a.clone() 16 </script> 17 </body> 18 </html>
坚持下去就能成功