What is Bind method in JavaScript
来源:互联网 发布:打卡机如何恢复数据 编辑:程序博客网 时间:2024/06/07 04:50
In this post we will take a look on Bind function in JavaScript. This method Bind a function to an Object.
For example if you have a function as following,
function FindSquare(number) {return number * number; }
And you have created an object as below,
var Calculator = {};
As you see that calculator object does not contain any properties or method. Now let us say you want to bind function FindSqaure to object Calculator then you can do that using Bind method in JavaScript.
- Bind method binds a function to object
- It returns a function after binding
So you can bind FindSquare function to Calculator object as below,
var CFindSquare = FindSquare.bind(Calculator);
Now when you call CFindSquare function and pass parameter, it will actually get passed to original function FindSquare.
You can invoke FindSquare method on object Calculator as follows,
var result = CFindSquare(8); alert(result);
In this way you can work with bind() method in JavaScript. I hope you find this post useful. Thanks for reading.
- What is Bind method in JavaScript
- What is apply() method in JavaScript
- what is the different between function and method in python
- What Is a Native Method?
- What is the Execution Context & Stack in JavaScript? [转载]
- What is the !! (not not) operator in JavaScript?
- What is JavaScript?
- JAVA中 什么是方法签名?what is method signature in java
- what is a synthetic field and method
- what is #pragma in c
- What is uadmin in Solaris?
- What is MultiSampleQuality in D3D
- what is Activity in Android
- What is “:-!!” in C code?
- What is 'lr_policy' in caffe?
- What is CountDownLatch in Java
- What is CyclicBarrier in Java
- What is EFF in BI
- C#,C++/CLR,C++三层
- Hive 中的日志
- unable to start program the specified file is an unrecognized or unsupported binary format
- Exchanger
- 问题三-查询界面,重置函数如何写(ok)
- What is Bind method in JavaScript
- android adb.exe程序启动不起来
- SI 、SP 帧介绍
- org.xmlpull.v1.XmlPullParserException: precondition: START_TAG
- 芯海芯片代码段
- JSP页面作用于范围及使用
- Linux hostname主机名配置文件/etc/hosts详解
- Android实现推送方式解决方案
- 一些开源引擎