SlideShare a Scribd company logo
Module Function
Function-bind bind(thisObj[, arg...]) -> Function Provides a guaranteed-binding equivalent of the original function, possibly with pre-filled arguments Prototype can guarantee that your function will execute with the object you want under the this reference, just by invoking bind on it  \ Example; This following  is a basic usage, just guaranteeing the reference:
Function-bind var  obj = {    name:  'A nice demo' ,    fx:  function () {      alert(this.name);    } }; window.name =  'I am such a beautiful window!' ;  function  runFx(f) {    f(); }   var  fx2 = obj.fx.bind(obj); runFx(obj.fx); runFx(fx2);
Function-bindAsEventListener  bindAsEventListener(thisObj[, arg...]) -> Function  An event-specific variant of  bind , which makes sure the function will get the current event object as first argument..   Prototype lets you bind a function as an event listener  Need to specify first what object is to be guaranteed as the this reference when the function executes  Prototype guarantees that its first argument will be the current event  Any arguments you specify in the remainder of your call to bindAsEventListener will appear next in the arguments list.
Function-bindAsEventListener Need to pass a method as an event listener.  Example; var  obj = {    name:  'A nice demo' ,    fx:  function (e) {      var  tag = Event.element(e).tagName.toLowerCase();      var  data =  $A (arguments).shift();      alert(this.name +  '\nClick on a '  + tag +  '\nOther args: '  + data.join( ', ' ));}};   Event.observe(document.body,  'click' , obj.fx.bindAsEventListener(obj,  1 ,  2 ,  3 )); // -> Any click on the page displays obj.name, the lower-cased tag name of the  //    clicked element, and "1, 2, 3".

More Related Content

PPTX
Javascript this keyword
PDF
C# 4.0 dynamic
PPS
Underscore
PPTX
PHP function
PPT
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
PDF
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
PDF
Practical TypeScript
PDF
Porting legacy apps to Griffon
Javascript this keyword
C# 4.0 dynamic
Underscore
PHP function
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Practical TypeScript
Porting legacy apps to Griffon

What's hot (20)

PDF
Runmodes and Configs for Fun and Profit
PPTX
Inline and lambda function
PPTX
Promises, promises, and then observables
PDF
Protocol in Swift
PDF
CFML Enhancements in ColdFusion 10
PPTX
h-ubu : CDI in JavaScript
KEY
Underscore.js
PDF
SCR Annotations for Fun and Profit
PDF
Wrapping java in awesomeness aka condensator
PPTX
Ruby Blocks
PPTX
h-ubu - CDI in JavaScript
PDF
Getting Comfortable with JS Promises
PDF
Json.parse() in JavaScript
PPTX
Twig + drupal 8
PPT
Php Coding Convention
PDF
みんなで Swift 復習会での談笑用スライド – 2nd #minna_de_swift
PDF
Practical JavaScript Promises
PDF
Efficiently exposing services on Kubernetes (part 2)
PPTX
Mule esb object_to_jackson_json
PDF
The Big Three
Runmodes and Configs for Fun and Profit
Inline and lambda function
Promises, promises, and then observables
Protocol in Swift
CFML Enhancements in ColdFusion 10
h-ubu : CDI in JavaScript
Underscore.js
SCR Annotations for Fun and Profit
Wrapping java in awesomeness aka condensator
Ruby Blocks
h-ubu - CDI in JavaScript
Getting Comfortable with JS Promises
Json.parse() in JavaScript
Twig + drupal 8
Php Coding Convention
みんなで Swift 復習会での談笑用スライド – 2nd #minna_de_swift
Practical JavaScript Promises
Efficiently exposing services on Kubernetes (part 2)
Mule esb object_to_jackson_json
The Big Three
Ad

Viewers also liked (7)

PPT
Php Sq Lite
PPT
Timedobserver
PPT
Periodicalexecuter
PPT
Object Range
PPT
PPT
Number
PPT
Php Crash Course
Php Sq Lite
Timedobserver
Periodicalexecuter
Object Range
Number
Php Crash Course
Ad

Similar to Function (20)

PPT
JavaScript Basics
PPTX
Oojs 1.1
PPTX
JavaScript (without DOM)
PDF
Uncommon Design Patterns
PPT
Diving in the Flex Data Binding Waters
PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
PPT
Advanced JavaScript
PPTX
4front en
PPTX
Closure
PPT
eXo SEA - JavaScript Introduction Training
PPT
Javascript Design Patterns
PPT
Introduction to Javascript
PDF
Advanced javascript
PDF
ES6 metaprogramming unleashed
PPT
jQuery with javascript training by Technnovation Labs
DOCX
descriptive programming
PPTX
Javascript And J Query
PPT
Javascript quiz. Questions to ask when recruiting developers.
PDF
Javascript Design Patterns
PDF
AngularJS application architecture
JavaScript Basics
Oojs 1.1
JavaScript (without DOM)
Uncommon Design Patterns
Diving in the Flex Data Binding Waters
Svcc Building Rich Applications with Groovy's SwingBuilder
Advanced JavaScript
4front en
Closure
eXo SEA - JavaScript Introduction Training
Javascript Design Patterns
Introduction to Javascript
Advanced javascript
ES6 metaprogramming unleashed
jQuery with javascript training by Technnovation Labs
descriptive programming
Javascript And J Query
Javascript quiz. Questions to ask when recruiting developers.
Javascript Design Patterns
AngularJS application architecture

More from mussawir20 (20)

PPT
Php Operators N Controllers
PPT
Php Calling Operators
PPT
Database Design Process
PPT
Php Simple Xml
PPT
Php String And Regular Expressions
PPT
Php Sessoins N Cookies
PPT
Php Rss
PPT
Php Reusing Code And Writing Functions
PPT
Php Oop
PPT
Php My Sql
PPT
Php File Operations
PPT
Php Error Handling
PPT
Php Basic Security
PPT
Php Using Arrays
PPT
Javascript Oop
PPT
Javascript
PPT
Prototype Utility Methods(1)
PPT
PPT
Prototype js
PPT
Template
Php Operators N Controllers
Php Calling Operators
Database Design Process
Php Simple Xml
Php String And Regular Expressions
Php Sessoins N Cookies
Php Rss
Php Reusing Code And Writing Functions
Php Oop
Php My Sql
Php File Operations
Php Error Handling
Php Basic Security
Php Using Arrays
Javascript Oop
Javascript
Prototype Utility Methods(1)
Prototype js
Template

Recently uploaded (20)

PPTX
Chapter 5: Probability Theory and Statistics
PPTX
A Presentation on Touch Screen Technology
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
August Patch Tuesday
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Chapter 5: Probability Theory and Statistics
A Presentation on Touch Screen Technology
Univ-Connecticut-ChatGPT-Presentaion.pdf
Approach and Philosophy of On baking technology
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Enhancing emotion recognition model for a student engagement use case through...
Getting Started with Data Integration: FME Form 101
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Heart disease approach using modified random forest and particle swarm optimi...
NewMind AI Weekly Chronicles - August'25-Week II
A novel scalable deep ensemble learning framework for big data classification...
August Patch Tuesday
cloud_computing_Infrastucture_as_cloud_p
Encapsulation_ Review paper, used for researhc scholars
A comparative analysis of optical character recognition models for extracting...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Programs and apps: productivity, graphics, security and other tools
DP Operators-handbook-extract for the Mautical Institute
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf

Function

  • 2. Function-bind bind(thisObj[, arg...]) -> Function Provides a guaranteed-binding equivalent of the original function, possibly with pre-filled arguments Prototype can guarantee that your function will execute with the object you want under the this reference, just by invoking bind on it \ Example; This following is a basic usage, just guaranteeing the reference:
  • 3. Function-bind var  obj = {    name:  'A nice demo' ,    fx:  function () {      alert(this.name);    } }; window.name =  'I am such a beautiful window!' ;  function  runFx(f) {    f(); }   var  fx2 = obj.fx.bind(obj); runFx(obj.fx); runFx(fx2);
  • 4. Function-bindAsEventListener bindAsEventListener(thisObj[, arg...]) -> Function  An event-specific variant of bind , which makes sure the function will get the current event object as first argument..   Prototype lets you bind a function as an event listener Need to specify first what object is to be guaranteed as the this reference when the function executes Prototype guarantees that its first argument will be the current event Any arguments you specify in the remainder of your call to bindAsEventListener will appear next in the arguments list.
  • 5. Function-bindAsEventListener Need to pass a method as an event listener. Example; var  obj = {    name:  'A nice demo' ,    fx:  function (e) {      var  tag = Event.element(e).tagName.toLowerCase();      var  data =  $A (arguments).shift();      alert(this.name +  '\nClick on a '  + tag +  '\nOther args: '  + data.join( ', ' ));}};   Event.observe(document.body,  'click' , obj.fx.bindAsEventListener(obj,  1 ,  2 ,  3 )); // -> Any click on the page displays obj.name, the lower-cased tag name of the  //    clicked element, and "1, 2, 3".