Skip to content

Instantly share code, notes, and snippets.

@nexpr
Created December 4, 2015 09:02
Show Gist options
  • Save nexpr/73becde53dc4500a512a to your computer and use it in GitHub Desktop.
Save nexpr/73becde53dc4500a512a to your computer and use it in GitHub Desktop.
!function(){
Object.prototype.mcall = function(method, bind_this){
var that = this
var this_to_arg = true
var fn = method
if(typeof fn === "string" && fn.charAt(0) === ":"){
fn = fn.substr(1)
bind_this = window
}
else if(arguments.length < 2){
bind_this = that
this_to_arg = false
}
if(typeof method !== "function"){
fn = (bind_this || window)[method]
}
return typeof fn === "function" ? function(){
var args = [].slice.call(arguments)
this_to_arg && args.unshift(that)
var res = fn.apply(bind_this, args)
return res == undefined ? new Undef : res
} : Undef.maker
}
Object.prototype._ = Object.prototype.mcall
Object.prototype.get = function(key){
return this[key]
}
Object.prototype.__ = function(key){
return this[key] == undefined ? new Undef : this[key]
}
function Undef(){
}
Undef.prototype.mcall = function(){
return Undef.maker
}
Undef.prototype.isUndef = true
Undef.maker = function(){
return new Undef
}
}()
;["ab", "c;de"]
._("pop")()
._("split")(";")
._("map")(function(e){return e+"-"})
._("join")("_")
._("getElementById", document)()
._("getChildIds", null)()
._("unshift")()
._(parseInt, window)(16)
._(":String")()
function getChildIds(elem){
return [].map.call(elem.children, function(e){return e.id})
}
;({0:10,1:11,2:12,length:3})
._(Array.prototype.slice)(1)
random_word()
._("match")(/sample-([a-f][0-9]+)/)
._("get")(1)
._("getElementsByClassName", document)()
._(Array.prototype.slice)()
._("sort")(function(a,b){return a.dataset.order - b.dataset.order}))
.__(4)
._("getAttribute")("id")
function random_word(){
var a = trueRate(50) ? "sample-" : strgen(6)
var b = trueRate(80) ? "c63" : strgen(3)
return a + b
function strgen(n){
return btoa(Math.random()).substr(0,n)
}
function trueRate(percent){
return Math.random()*100 < percent
}
}
a.__("b").__("c").__("d")
var v = x._("match")(/[0-9]+/).__(1)
if(!v.isUndef){
y(v)
}
var val = v.isUndef ? undfined : v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment