关于 top 给全局增加方法

 top 和 Window  一样 是一个全局的顶级对象 应该是jq里面设置的

下面是打印的

console.log(top)

VM602:1 Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}

$: ƒ ( selector, context )
alert: ƒ alert()
applicationCache: ApplicationCache {status: 0, oncached: null, onchecking: null, ondownloading: null, onerror: null, …}
atob: ƒ atob()
blur: ƒ ()
btoa: ƒ btoa()
caches: CacheStorage {}
cancelAnimationFrame: ƒ cancelAnimationFrame()
cancelIdleCallback: ƒ cancelIdleCallback()
captureEvents: ƒ captureEvents()
chrome: {loadTimes: ƒ, csi: ƒ}
clearInterval: ƒ clearInterval()
clearTimeout: ƒ clearTimeout()
clientInformation: Navigator {vendorSub: "", productSub: "20030107", vendor: "Google Inc.", maxTouchPoints: 0, hardwareConcurrency: 4, …}
close: ƒ ()
closed: false
confirm: ƒ confirm()
createImageBitmap: ƒ createImageBitmap()
crypto: Crypto {subtle: SubtleCrypto}
customElements: CustomElementRegistry {}
defaultStatus: ""
defaultstatus: ""
devicePixelRatio: 1
document: document
external: External {}
fetch: ƒ fetch()
find: ƒ find()
focus: ƒ ()
frameElement: null
frames: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
getComputedStyle: ƒ getComputedStyle()
getSelection: ƒ getSelection()
history: History {length: 1, scrollRestoration: "auto", state: null}
indexedDB: IDBFactory {}
innerHeight: 969
innerWidth: 543
isSecureContext: true
jQuery: ƒ ( selector, context )
layer: {v: "3.1.1", ie: false, index: 0, path: "http://localhost:63342/a-%E6%A1%8C%E9%9D%A2/ss-jq/js/layer/", config: ƒ, …}
length: 0
localStorage: Storage {length: 0}
location: Location {replace: ƒ, href: "http://localhost:63342/a-%E6%A1%8C%E9%9D%A2/ss-jq/01.html?_ijt=l9tmjq2tqe2dr9bukt137mo2oo", ancestorOrigins: DOMStringList, origin: "http://localhost:63342", protocol: "http:", …}
locationbar: BarProp {visible: true}
matchMedia: ƒ matchMedia()
menubar: BarProp {visible: true}
moveBy: ƒ moveBy()
moveTo: ƒ moveTo()
name: ""
navigator: Navigator {vendorSub: "", productSub: "20030107", vendor: "Google Inc.", maxTouchPoints: 0, hardwareConcurrency: 4, …}
onabort: null
onafterprint: null
onanimationend: null
onanimationiteration: null
onanimationstart: null
onappinstalled: null
onauxclick: null
onbeforeinstallprompt: null
onbeforeprint: null
onbeforeunload: null
onblur: null
oncancel: null
oncanplay: null
oncanplaythrough: null
onchange: null
onclick: null
onclose: null
oncontextmenu: null
oncuechange: null
ondblclick: null
ondevicemotion: null
ondeviceorientation: null
ondeviceorientationabsolute: null
ondrag: null
ondragend: null
ondragenter: null
ondragleave: null
ondragover: null
ondragstart: null
ondrop: null
ondurationchange: null
onemptied: null
onended: null
onerror: null
onfocus: null
ongotpointercapture: null
onhashchange: null
oninput: null
oninvalid: null
onkeydown: null
onkeypress: null
onkeyup: null
onlanguagechange: null
onload: null
onloadeddata: null
onloadedmetadata: null
onloadstart: null
onlostpointercapture: null
onmessage: null
onmessageerror: null
onmousedown: null
onmouseenter: null
onmouseleave: null
onmousemove: null
onmouseout: null
onmouseover: null
onmouseup: null
onmousewheel: null
onoffline: null
ononline: null
onpagehide: null
onpageshow: null
onpause: null
onplay: null
onplaying: null
onpointercancel: null
onpointerdown: null
onpointerenter: null
onpointerleave: null
onpointermove: null
onpointerout: null
onpointerover: null
onpointerup: null
onpopstate: null
onprogress: null
onratechange: null
onrejectionhandled: null
onreset: null
onresize: null
onscroll: null
onsearch: null
onseeked: null
onseeking: null
onselect: null
onselectionchange: null
onselectstart: null
onstalled: null
onstorage: null
onsubmit: null
onsuspend: null
ontimeupdate: null
ontoggle: null
ontransitionend: null
onunhandledrejection: null
onunload: null
onvolumechange: null
onwaiting: null
onwebkitanimationend: null
onwebkitanimationiteration: null
onwebkitanimationstart: null
onwebkittransitionend: null
onwheel: null
open: ƒ open()
openDatabase: ƒ ()
opener: null
origin: "http://localhost:63342"
outerHeight: 1040
outerWidth: 1920
pageXOffset: 0
pageYOffset: 0
param: ""
parent: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
performance: Performance {timeOrigin: 1564649978605.885, onresourcetimingbufferfull: null, memory: MemoryInfo, navigation: PerformanceNavigation, timing: PerformanceTiming}
personalbar: BarProp {visible: true}
postMessage: ƒ ()
print: ƒ print()
prompt: ƒ prompt()
queueMicrotask: ƒ queueMicrotask()
releaseEvents: ƒ releaseEvents()
requestAnimationFrame: ƒ requestAnimationFrame()
requestIdleCallback: ƒ requestIdleCallback()
resizeBy: ƒ resizeBy()
resizeTo: ƒ resizeTo()
screen: Screen {availWidth: 1920, availHeight: 1040, width: 1920, height: 1080, colorDepth: 24, …}
screenLeft: 0
screenTop: 0
screenX: 0
screenY: 0
scroll: ƒ scroll()
scrollBy: ƒ scrollBy()
scrollTo: ƒ scrollTo()
scrollX: 0
scrollY: 0
scrollbars: BarProp {visible: true}
self: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
sessionStorage: Storage {length: 0}
setInterval: ƒ setInterval()
setTimeout: ƒ setTimeout()
speechSynthesis: SpeechSynthesis {pending: false, speaking: false, paused: false, onvoiceschanged: null}
ssMethod: {changeUrlParam: ƒ, setArr: ƒ, loadStyles: ƒ, isMobilePhone: ƒ}
status: ""
statusbar: BarProp {visible: true}
stop: ƒ stop()
styleMedia: StyleMedia {type: "screen"}
toolbar: BarProp {visible: true}
top: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
type: "GET"
visualViewport: VisualViewport {offsetLeft: 0, offsetTop: 0, pageLeft: 0, pageTop: 0, width: 543, …}
webkitCancelAnimationFrame: ƒ webkitCancelAnimationFrame()
webkitRequestAnimationFrame: ƒ webkitRequestAnimationFrame()
webkitRequestFileSystem: ƒ ()
webkitResolveLocalFileSystemURL: ƒ ()
webkitStorageInfo: DeprecatedStorageInfo {}
window: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
_http: {asyncGet: ƒ, get: ƒ, asyncPost: ƒ, post: ƒ, async: ƒ}

 给全局增加方法 如下

打印 top或者window

_http:
async: ƒ (url, param, type, callback)
asyncGet: ƒ (url, param, callback)
asyncPost: ƒ (url, param, callback)
get: ƒ (url, param)
post: ƒ (url, param, callback)
arguments: (...)
caller: (...)
length: 3
name: "post"
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: ss-http.js:111
[[Scopes]]: Scopes[2]
__proto__: Object
Infinity: Infinity

/*
 * 描 述:操作类
 */
top._http= (function ($) {
    "use strict";
    var httpCode = {
        success: 200,
        fail: 400,
        exception: 500,
        state:"success"
    };
    var exres = { code: httpCode.exception, info: '通信异常,请联系管理员!' }
    var Dream = {
        asyncGet: function (url, param, callback) {//纠结 这个param 去掉是不是更好
            if ( $.isFunction( param) ) {//如果没有param参数 把param改成callback
                callback = param;
                param = undefined;
            }
            $.ajax({
                url: url,
                data: param,
                type: "GET",
                dataType: "json",
                async: true,
                cache: false,
                success: function (data,status) {
                    // if (data.state == "success") {//判断返回数据是否异常 ps(目前判断方法(data.state == "success")根据目前后台判断标准 )
                    //有些接口是返回一个数组 没有data.state 这里要特殊处理一下
                    if (data.state == httpCode.state || !data.state&&status== httpCode.state) {
                        callback(data);
                    }else {
                        layer.alert(data.message||exres.info, { icon: 5 });//数据异常弹窗
                        callback(null);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {//非200报错
                    layer.alert(exres.info, { icon: 5 });
                    callback(null);
                },
                beforeSend: function () {
                    //发送请求前
                },
                complete: function () {
                    //请求完成时运行的函数(在请求成功或失败之后均调用,即在 success 和 error 函数之后)。
                }
            });
        },
        // get请求方法(同步):url地址,param参数 返回  t同步就简化去掉回调 直接得值
        get: function (url, param) {
            var res = {};
            $.ajax({
                url: url,
                data: param,
                type: "GET",
                dataType: "json",
                async: false,
                cache: false,
                success: function (data,status) {
                    if (data.state == httpCode.state || !data.state&&status== httpCode.state) {
                        res = data;
                    }else {
                        layer.alert(data.message||exres.info, { icon: 5 });//后台管理的异常弹窗
                        res = null;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(exres.info, { icon: 5 });
                    res = null;
                },
                beforeSend: function () {
                },
                complete: function () {
                }
            });
            return res;
        },
        // post请求方法(异步):url地址,param参数,callback回调函数
        asyncPost: function (url, param, callback) {
            if ( $.isFunction( param) ) {//如果没有param参数 把param改成callback
                callback = param;
                param = undefined;
            }
            $.ajax({
                url: url,
                data: param,
                type: "POST",
                dataType: "json",
                async: true,
                cache: false,
                success: function (data,status) {//有的接口会直接返回数组 没有data.state
                    // console.log(status ) 当前项目不适合用status
                    //!data.state&&status== "success" 判断返回数据为数组或者其他 切 没有其他接口一样有 data.state
                    if (data.state == httpCode.state || !data.state&&status== httpCode.state) {
                        callback(data);
                    }else {
                        layer.alert(data.message||exres.info, { icon: 5 });
                        callback(null);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(exres.info, { icon: 5 });
                    callback(null);
                },
                beforeSend: function () {
                },
                complete: function () {
                }
            });
        },
        // post请求方法(同步):url地址,param参数,callback回调函数
        post: function (url, param, callback) {
            if ( $.isFunction( param) ) {//如果没有参数 把param改成callback
                callback = param;
                param = undefined;
            }
            $.ajax({
                url: url,
                data: param,
                type: "POST",
                dataType: "json",
                async: false,
                cache: false,
                success: function (data,status) {
                    if (data.state == httpCode.state || !data.state&&status== httpCode.state) {
                        callback(data);
                    }else {
                        layer.alert(data.message||exres.info, { icon: 5 });
                        callback(null);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(exres.info, { icon: 5 });
                    callback(null);
                },
                beforeSend: function () {
                },
                complete: function () {
                }
            });
        },
        // ajax 异步封装 url 参数 请求类型
        async: function (url, param, type, callback) {
            $.ajax({
                url: url,
                data: param,
                type: type,
                dataType: "json",
                async: true,
                cache: false,
                context: param,
                success: function (data) {
                    if (data.state == httpCode.state || !data.state&&status == httpCode.state) {
                        callback.apply(this, [data]);
                    }
                    else {
                        layer.alert(data.message||exres.info, { icon: 5 });
                        callback.apply(this);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    callback(null);
                    layer.alert(exres.info, { icon: 5 });
                },
                beforeSend: function () {
                },
                complete: function () {
                }
            });
        },


    };
    return Dream;
})(window.jQuery);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值