this

Understanding use of “this” in java

我们两清 提交于 2019-12-11 12:38:39
问题 I'm trying to understand the this keyword in java. I wanted to rewrite this code by using the this keyword instead. Please let me know if I've done it right. Here's the original code: public class Book { private String title; private String author; private String publisher; public Book(String bookTitle, String authorName, String publisherName){ title = bookTitle; author = authorName; publisher = publisherName; } } And here's the re-written code: public class Book { private String title;

Why doesn't javascript “this” work with “each”?

假如想象 提交于 2019-12-11 12:24:06
问题 I'm trying to assign a class to an element upon detecting that it has a data-voted attribute of "true" , but the simple addClass line is not working. I was using $(this) until I read jQuery's documentation for each() , and then switched to the following: windowReady = -> jQuery -> $voteLinks = $('.vote-button a') $voteLinks.each (i, current) -> if $(current).data('voted') == "true" $(current).addClass('voted') $(window).load(windowReady); $(window).on('page:load', windowReady); $(this)

How $this works in .phtml files in zend framework?

帅比萌擦擦* 提交于 2019-12-11 12:13:28
问题 For all my practice with OOP I have never used $this outside of the class definition. While in zendframework we use $this in view template files, obviously it is not the scope of a class definition. I wonder how it has been implemented ? I have googled a lot but got no luck. I want to know the mechanism how zendframework renders it's view files with $this. 回答1: It actually is in the scope of a class definition. Simple test-case: <?php // let's call this view.php class View { private $variable

ReactJS - this.functionname is not a function

假如想象 提交于 2019-12-11 11:49:04
问题 I have a listener setup in my componentDidMount: updateBasketTotal: function() { BasketService.getBasketTotal(function(data){ this.setState({ selectedPeopleCount: data.TotalMembers }); }.bind(this)); }, componentDidMount: function() { this.updateBasketTotal(); this.subscribeToChannel(basketChannel,"selectAll",this.listenerSelectAll); this.subscribeToChannel(basketChannel,"removePersonFromBasket",this.listenerRemovePersonFromBasket); this.subscribeToChannel(basketChannel,"addPersonToBasket"

C++ 'this' and operator overloading

心已入冬 提交于 2019-12-11 10:55:27
问题 I was wondering how can you use operators along with 'this'. To put an example: class grd : clm { inline int &operator()(int x, int y) { return g[x][y]; } /* blah blah blah */ }; grd grd::crop(int cx1, int cy1, int cx2, int cy2) { grd ngrd(abs(cx1-cx2), abs(cy1-cy2)); int i, j; // for (i = cx1; i < cx2; i++) { for (j = cy1; j < cy2; j++) { if (i >= 0 && i < x && j >= 0 && j < y) ngrd(i-cx1,j-cy2) = ?? // this->(i,j); **** } } return ngrd; } Thanks! 回答1: Either: this->operator()(i,j) or (*this

jQuery plugin, context and setTimeout

与世无争的帅哥 提交于 2019-12-11 08:49:16
问题 I'm writing a plugin for jQuery and I have a mess in my head with the context issue in javascript. This is a simplified version of my plugin: (function($){ $.fn.myplugin = function(options){ return new MyPlugin(this, options); }; function MyPlugin(el, o ) { this.root = el; this.input_box = el.find('#the_input'); this.map = null; this.timeout = null; var self = this; self.input_box.keyup( function(){ if( self.timeout!==null ) { clearTimeout( self.timeout ); } self.timeout = setTimeout(

using the 'this' variable within object constructor

家住魔仙堡 提交于 2019-12-11 08:17:50
问题 I'm a bit confused on the result I'm getting when calling the 'this' variable inside in object constructor. function Slider(tag){ this.tag = document.querySelector(tag), this.start = function(){ return this.interval; }, this.interval = setInterval(function(){ console.log(this.tag); //undefined console.log(this); //window object }, 2000) } var route ={ init:function(){ mySlide = new Slider('slider'); mySlide.start(); } } document.addEventListener('DOMContentLoaded', route.init); I'm logging

'this' pointer in macro and function

房东的猫 提交于 2019-12-11 06:25:33
问题 I have some code which use 'this' pointer of class which calls this code. For example: Some::staticFunction<templateType>(bind(FuncPointer, this, _1)); Here is I'm calling bind function from boost. But it doesn't matter. Now I have to wrap this code. I made a macro: #define DO(Type, Func) Some::staticFunction<Type>(bind(FuncPointer, this, _1)); And compiler insert this code into class which calls this macro, so 'this' takes from caller. But I don't want to use macro and prefer function

Redirecting to a dynamic method from a generic event handler

末鹿安然 提交于 2019-12-11 05:29:15
问题 I'm trying to write a class that's to be used to trigger a call to a method from an arbitrary event but I'm stuck as I simply cannot figure out a way to reference 'this' from emitted MSIL code. This example should describe what I'm looking for: class MyEventTriggeringClass { private object _parameter; public void Attach(object source, string eventName, object parameter) { _parameter = parameter; var e = source.GetType().GetEvent(eventName); if (e == null) return; hookupDelegate(source, e); }

Get ID from this.parent

99封情书 提交于 2019-12-11 04:59:29
问题 Trying to get the id name of a div using javascript when it is going by $(this).parent(). Javascript Code below: $(function() { $('a.close').click(function() { $(this).parent().fadeOut(1500); $.cookie($(this).attr('id'), 'true', { expires: null}); alert($.cookie($(this).attr('id'))); return false; }); if($.cookie('hidden') == 'true'){ $('#errororganinfoinchide-this').hide(); } }); Trying to get the id errororganinfoinchide-this from the HTML below. Trying this way as that id can vary from