Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > BOOK: HTML5, JavaScript and jQuery 24-Hour Trainer
| Search | Today's Posts | Mark Forums Read
BOOK: HTML5, JavaScript and jQuery 24-Hour Trainer
This is the forum to discuss the Wrox book HTML5, JavaScript and jQuery 24-Hour Trainer by Dane Cameron; ISBN: 978-1-119-00116-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: HTML5, JavaScript and jQuery 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 26th, 2016, 04:43 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default What does "this" refer to in the code of page 168

Background info: author has summarized 4 scenarios of "this" on page 131. In short, a)in a regular function b)in a method of a object c)in constructor function and d)when bind is used.

"this" is used in 2 places in this code:
1) var contact = this.serializeForm();
Is "this" a a) regular function? If it's in a regular function, it refers to window object. Does window object have access to serializeForm()?

2) ...}.bind(this)
bind() is called on function(evt). function(evt) is an event listener or callback function to handle click event of submit button. On page 131, author says that "this" when used with bind() refers to the object passed as an argument into bind(). But what is this object that "this" refers to?
  #2 (permalink)  
Old May 27th, 2016, 03:10 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, text following the code answers my question. If without the ...}.bind(this), the 'this' inside function(evt) would be referring to window object. "this" passed in bind() refers to form object. But here brings up another interesting question: does form object owns serializeForm()?


Similar Threads
Thread Thread Starter Forum Replies Last Post
Base Page Problem with "safeitenames" carryover in the 'inherits" johnandrewmcknight BOOK: Beginning ASP.NET 4 : in C# and VB 3 April 22nd, 2011 04:08 PM
Need code corrections "get sub or function not defined" error" bluesboytoo Excel VBA 1 October 22nd, 2009 11:12 PM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM
How to download Code in "Professional Active Server Page 3.0 " book. renjith0 All Other Wrox Books 2 April 2nd, 2009 05:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.