{"id":687,"date":"2017-08-07T21:00:40","date_gmt":"2017-08-07T13:00:40","guid":{"rendered":"http:\/\/loveuhouse.cn\/wordpress\/?p=687"},"modified":"2017-08-07T21:00:40","modified_gmt":"2017-08-07T13:00:40","slug":"js-%e6%a8%a1%e6%8b%9fjq-%e5%ae%9e%e7%8e%b0-%e9%80%89%e6%8b%a9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/loveuhouse.cn\/wordpress\/?p=687","title":{"rendered":"js \u6a21\u62dfjq \u5b9e\u73b0 $ \u9009\u62e9\u5668"},"content":{"rendered":"<pre class=\"lang:js decode:true\">\n(function(){\n    var jQ = function(selector, father){\n        return new jQ.prototype.init(selector);\n    };\n    jQ.prototype = {\n        length:0,\n        init:function(selector, father){\n            var _document = father || ja.view,\n                classInt = 0,\n                res = this;\n            if (typeof selector != \"string\" || !selector ){\n                if(typeof selector == \"object\" && selector.hasOwnProperty(\"length\")){\n                    for(var i = 0 ; i < selector.length ; i++){\n                        this[classInt] = selector[i];\n                        classInt++;\n                    }\n                }else{\n                    this[classInt] = selector;\n                    classInt++;\n                }\n\n            }else{\n                var props = selector.trim().split(\" \"),\n                    selector = props.shift(),\n                    selectLast = props.join(\" \"),\n                    mark = selector.charAt(0);\n                if(mark == \"[\"){\n                    var selector=selector.replace(\/[\\[\\]]\/g,\"\"),\n                        arr = selector.split(\"=\");\n                    key = arr.length > 1 ? arr[0].trim() : \"name\",\n                        val = arr.length > 1 ? arr[1].trim() : arr[0].trim();\n                    \/\/\u904d\u5386children\n                    \/\/ ja.log(key,val);\n                    _document.children.map(function(ele){\n                        return (function(father,deep){\n                            \/\/ var res = [];\n                            if(typeof father[key] !=\"undefined\" && father[key] == val){\n\n                                this[classInt] = father;\n                                classInt++;\n                            }\n                            var c = father.children;\n                            if(c && deep < 5){\n                                deep++;\n                                for(var i in c){\n                                    arguments.callee.call(this,c[i],deep);\n                                }\n                            }\n                            \/\/ return res;\n                        }).call(this,ele,0);\n                    }.bind(this))\n                }else if(mark == \".\"){\n                    var res = this.__class(selector.substring(1));\n                    res.map(function(ele){\n                        this[classInt] = ele;\n                        classInt++;\n                    }.bind(this));\n\n                }\n            }\n            this.length = classInt;\n            return this;\n        },\n        \/*\u539f\u578b\u65b9\u6cd5\uff0c\u4e0d\u66b4\u9732*\/\n        \/\/\u7c7b\u9009\u62e9\u5668\u4f4d\u7f6e\u5217\u8868\n        __class:function(className){\n            var arr = [];\n            switch (className){\n                case \"mainView\":\n                    arr.push(ja.view);\n                    break;\n                case \"setBalance\":\n                    arr.push(ja.setb);\n                    break;\n                case \"gameBalance\":\n                    arr.push( ja.gameb);\n                    break;\n                case \"playerFrameList\":\n                    for(var key in ja.view.playerInfoHandler.playerFrameList){\n                        arr.push(ja.view.playerInfoHandler.playerFrameList[key].view);\n                    }\n                    break;\n                case \"playerArea\":\n                    arr.push( ja.view.posLocal2Player);\n                    break;\n                case \"playerOut\":\n                    ja.view.posLocal2Player.map(function(ele){\n                        arr.push( ele.outTile);\n                    });\n                    break;\n                default:\n                    return null\n            }\n            return arr;\n        },\n        \/\/\u901a\u8fc7\u9009\u62e9\u5668\u786e\u5b9a\u5b50\u5143\u7d20\u83b7\u53d6\u65b9\u5f0f\n        _selector: function(selector, father){\n            if(typeof selector != \"string\" || !selector){\n                return this;\n            }\n            father = father ? father.children : Array.prototype.slice.apply(this);\n            var mark = selector.charAt(0);\n            switch(mark){\n                case \"[\":\n                    var reg = \/\\[(([\\w\\W]+)=[\"']?([\\w\\W]+)[\"']?|([\\w\\W]+))\\]\/;\n                    var reg_res = reg.exec(selector);\n                    var res_key = reg_res[2] || \"name\";\n                    var res_val = reg_res[3] || reg_res[4];\n                    var res = [];\n                    father.map(function(ele){\n                        return (function(fa, deep){\n\n                            if(typeof fa[res_key] != \"undefined\" && fa[res_key] == res_val){\n                                res.push(fa);\n                            }\n\n                            if (fa.children.length > 0 && deep < 5){\n                                deep++;\n                                for( var i = 0 ; i < fa.children.length ; i++){\n                                    var add = arguments.callee.call(this,fa.children[i],deep);\n                                }\n                            }\n                            return res;\n                        }).call(this,ele,0);\n                    }.bind(this));\n\n                    return res;\n                case \":\":\n\n                    break;\n                case \"*\":\n\n                    break;\n                default:\n\n            }\n        },\n        \/\/\u8868\u8fbe\u5f0f\u7b5b\u9009\u5668\uff0c\u672a\u5b8c\u6210\n        _expression:function(expression){\n            if(!expression){\n\n            }\n            switch (expression){\n                case \"first\":\n                    return 0;\n                case \"last\":\n                    return\n            }\n        },\n        \/*\u8fc7\u6ee4*\/\n        find:function(selector){\n            var res = this._selector(selector);\n            return new jQ.prototype.init(res);\n        },\n        parent:function(){\n            var arr = [];\n            Array.prototype.slice.apply(this).map(function(ele,ind){\n                arr.push(ele[\"parent\"]);\n            }.bind(this));\n            if(arr.length > 0){\n                var res = arr.length == 1 ? arr.shift() : arr;\n                return new jQ.prototype.init(res);\n            }\n        },\n        parents:function(){\n\n        },\n        child:function(selector){\n\n        },\n        \/*\u64cd\u4f5c*\/\n        attr:function(selector, setValue){\n            var arr = [];\n            Array.prototype.slice.apply(this).map(function(ele,ind){\n                if(typeof setValue == \"undefined\"){\n                    if(typeof ele[selector] != \"undefined\"){\n                        arr.push(ele[selector]) ;\n                    }else if(typeof ele[\"_\"+selector] != \"undefined\"){\n                        arr.push(ele[\"_\"+selector]) ;\n                    }\n\n                }else{\n                    ele[selector] = setValue;\n                }\n            }.bind(this));\n            if(arr.length > 0){\n                return arr.length == 1 ? arr.shift() : arr;\n            }\n        },\n        hide:function(){\n            Array.prototype.slice.apply(this).map(function(ele){\n                ele.setVisible(false);\n            })\n        },\n        show:function(){\n            Array.prototype.slice.apply(this).map(function(ele){\n                ele.setVisible(true);\n            })\n        },\n    };\n    jQ.prototype.init.prototype = jQ.prototype;\n    return window.$ = jQ;\n})()\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>(function(){ var jQ = function(selector, father){ retur &hellip; <a href=\"https:\/\/loveuhouse.cn\/wordpress\/?p=687\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">js \u6a21\u62dfjq \u5b9e\u73b0 $ \u9009\u62e9\u5668<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/687"}],"collection":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=687"}],"version-history":[{"count":1,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":688,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/687\/revisions\/688"}],"wp:attachment":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}