免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
屬性擴(kuò)展-入門
//property 屬性 可以向?qū)ο筇砑訉傩院头椒?/b>
function employee(name,job,born){
this.name = name;
this.job = job;
this.born = born;
}
var bill = new employee("Bill Gates","Engineer","1985");
employee.prototype.salary = null;
bill.salary = 2000;
console.log(bill);
console.log(bill.salary);
var arr = [1,2,3,5,6,32];
//為腳本環(huán)境內(nèi)建對(duì)象添加方法
Array.prototype.max = function(){
var i,max = this[0];
for(i=0;i<this.length;i++){
if(max<this[i]){
max = this[i];
}
}
return max;
}
console.log(arr.max());
//為用戶自定義類添加方法
function TestObjet(name){
this.name = name;
}
TestObjet.prototype.ShowName = function(){
alert(this.name);
}
var testObj = new TestObjet("Tom");
testObj.ShowName();
//對(duì)象間實(shí)現(xiàn)繼承
function TestObjA () {
this.MethodA = function(){
alert("TestObjA.methodA");
}
}
function TestObjB () {
this.MethodB = function(){
alert("TestObjB.methodB");
}
function TestObjC () {
this.MethodC = function(){
alert("TestObjC.methodC");
}
}
TestObjB.prototype.a = new TestObjA();
TestObjB.prototype.c = new TestObjC();
var myObj = new TestObjB();
myObj.a.MethodA();
myObj.MethodB();
myObj.c.MethodC();
//為js對(duì)象擴(kuò)展
console.log("為js對(duì)象擴(kuò)展");
Number.prototype.add = function(num){
return this+num;
}
console.log((3).add(5));
//js 為Boolean 對(duì)象添加“布爾值取反”功能
console.log("js 為Boolean 對(duì)象添加“布爾值取反”功能");
Boolean.prototype.rev=function(){
return !this;
}
console.log((true).rev());
//為Array對(duì)象添加“在數(shù)組末尾加入一個(gè)新的元素”功能
Array.prototype.push = function(ele){
this[this.length] = ele;
return this;
}
Array.prototype.pushPro = function(){
var currenLength = this.length;
for(var i=0;i<arguments.length;i++){
this[currenLength+i] =arguments[i];
}
return this.length;
}
var arr=[1,2,3];
arr.push(4);
console.log(arr);
arr.pushPro(5,6,7);
console.log(arr);
//js 日期格式獲取
Date.prototype.format = function(fmt) {
var o = {
"M+":this.getMonth()+1,     //月份
"d+":this.getDay(),
"h+":this.getHours(),
"m+":this.getMinutes(),
"s+":this.getSeconds(),
"q+":Math.floor((this.getMonth()+3/3)),   //季度
"S":this.getMilliseconds()       //毫秒
};
if(/(y+)/.test(fmt)) {
           fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
   }
   for(var k in o) {
       if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
   return fmt; 
}
var time = new Date().format("yyyy-MM-dd hh:mm:ss");
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服