本文整理汇总了TypeScript中jQuery.proxy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript proxy函数的具体用法?TypeScript proxy怎么用?TypeScript proxy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了proxy函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: listenTo
/*
Given an `other` object that has on/off methods, bind the given `callback` to an event by the given name.
The `callback` will be called with the `this` context of the object that .listenTo is being called on.
Can be called:
.listenTo(other, eventName, callback)
OR
.listenTo(other, {
eventName1: callback1,
eventName2: callback2
})
*/
listenTo(other, arg, callback?) {
if (typeof arg === 'object') { // given dictionary of callbacks
for (let eventName in arg) {
if (arg.hasOwnProperty(eventName)) {
this.listenTo(other, eventName, arg[eventName])
}
}
} else if (typeof arg === 'string') {
other.on(
arg + '.' + this.getListenerNamespace(), // use event namespacing to identify this object
$.proxy(callback, this) // always use `this` context
// the usually-undesired jQuery guid behavior doesn't matter,
// because we always unbind via namespace
)
}
}
示例2: function
typeahead.lookup = function() {
this.query = this.$element.val() || '';
var items = this.source(this.query, $.proxy(this.process, this));
return items ? this.process(items) : items;
};