function bind(self, fn) {
var slice = [].slice;
var curryArgs = arguments.length > 2
? slice.call(arguments, 2, arguments.length)
: [];
if (typeof fn == "function" && !(fn instanceof RegExp)) {
return curryArgs.length
? function() {
return arguments.length
? fn.apply(self, curryArgs.concat(slice.call(arguments, 0, arguments.length)))
: fn.apply(self, curryArgs);
}
: function() {
return arguments.length
? fn.apply(self, arguments)
: fn.call(self);
};
} else {
// in IE, native methods are not functions and so they can not be bound (but they don't need to be)
return fn;
}
}
function Foo(name){
this.name= name;
}
var print = function (prefix){
console.log(prefix+this.name);
}
var cat = new Foo("cat");
var printCat = bind(cat, print, "I am a "); //printCat will always be bound to cat from now on.
printCat(); // I am a cat
function zoo(printCat){
printCat();
}
zoo(printCat);// where ever we use the function printCat, it is bound to cat
分享到:
相关推荐
How to bind data to different DataTemplate in Universal Windows Platform apps
Manage code organization using modules and component dependencies with the Dependency Injection Framework, Find out how to use AngularJS directives to extend the behavior of HTML on your web page, ...
From there, we'll move on to some advanced patterns for object creation and you'll get a strong idea of how to use interesting patterns to present data to users and to bind data. We'll use the famous...
A name-to-object association is called a name binding. A name binding is always defined relative to a naming context. A naming context is an object that contains a set of name bindings in which each ...
Unable to load class ‘javax.xml.bind.JAXBException‘(csdn)
How can we use a class Foo in a header file without access to its definition? We can declare data members of type Foo* or Foo&. We can declare (but not define) functions with arguments, and/or ...
From Zero to ARM Assembly Bind Shellcode 英文版
* How to bind visual elements to data sources. * How to perform graphics transformations to produce eye–catching displays, and how to use animation to produce pages that are alive with action. * ...
This book focuses on running DNS systems based on BIND 9.3.0the first stable release that includes support for the latest DNSSEC (DNSSEC...standards and a major functional upgrade from previous BIND 9 releases....
Wifi (802.11) In a wireless LAN, wireless users transmit/receive packets to/from an base station (i.e., wireless access point) within a radius of few tens of meters. The base station is typically ...
├最新AngularJS开发宝典—第006讲 表达式与ng-bind及ng-cloak解决闪屏问题.mp4 ├最新AngularJS开发宝典—第007讲 ng-model在表单中双向绑定实例分析讲解.mp4 ├最新AngularJS开发宝典—第008讲 ng-value的使用实例...
scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) { data...
DNS服务器搭建的bind安装包,适用于windows操作系统安装,官方版。
bind bind bind bind
a pooling library, an Object-Directory Mapping (ODM) framework, an LDIF parsing library with Spring Batch integration, exception translation from NamingExceptions to a mirrored unchecked Exception ...
Data Access - How-To Create a Database Data Access - N-Tier Data Form and Data Layer Data Access - Read and Write Images from a Database Data Access - Retreive and Process data with a SQL Data Reader ...
Chapter 4, Implementing Properties and Events in our Components, covers how to send data to components and how to bind methods to them so that the components have the ability to communicate upstream. ...
互联网的最基础和最重要的资源服务器;网络工程师的必要基础