this

PHP copy all object properties to this

不打扰是莪最后的温柔 提交于 2020-04-07 14:46:27
问题 I have an object in PHP, of the type MyObject . $myObject instanceof MyObject Now, in the class MyObject , there is a non-static function, and in there, I use the reference to "me", like $this , but I also have another object there. Is it possible, without doing $this = $myObject , to achieve more or less the same effect, like something of the sort set_object_vars($this, get_object_vars($myObject)) ? 回答1: <?php class MyObject { public function import(MyObject $object) { foreach (get_object

addEventListener, arrow functions, and `this` [duplicate]

只谈情不闲聊 提交于 2020-04-06 06:49:48
问题 This question already has answers here : What does “this” refer to in arrow functions in ES6? (7 answers) Closed 3 years ago . I'm going through the JavaScript30 challenge, and in lesson 3 he's got some event listener calling a function that references the element it's called on as this : const inputs = document.querySelectorAll('.controls input'); function handleUpdate() { const suffix = this.dataset.sizing || ''; document.documentElement.style.setProperty(`--${this.name}`, this.value +

Java - 'this' operator [closed]

喜欢而已 提交于 2020-03-03 09:12:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I have a question about the this operator in Java. In the case where a programmer would write a code like this: private int counter;

Java - 'this' operator [closed]

久未见 提交于 2020-03-03 09:12:12
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I have a question about the this operator in Java. In the case where a programmer would write a code like this: private int counter;

JavaScript设计模式之二:this、call和apply

早过忘川 提交于 2020-03-01 10:28:52
(本节内容摘自:Javascript设计模式与开发实践一书,作为自己的笔记保存,希望对有需要的朋友有用) this、call和apply在Javascript编程中应用非常广泛,所以,我们必须先了解它们。 一、this Javascript中的this总是指向一个对象,而它又是基于执行环境动态绑定,以下有4中情况可以用来分析。 当函数作为对象的方法时,this指向该对象,看下面的代码: var obj = { a: 1, getA: function(){ alert(this === obj); //true alert(this.a); //1 } }; obj.getA(); 当作为普通函数调用时,此时的this总是指向全局对象window window.name = 'globalName'; var getName = function(){ return this.name; }; console.log(getName()); //globalName 下面来一个实际的例子,我们在一个div节点内部,定义一个局部的callback方法,当这个方法被当做普通函数调用时,callback内部的this就指向了window,如下代码: <html> <body> <div id="div1">我是一个Div</div> </body> <script> window.id

Context and variable scope in ES6 loops and forEach

时光毁灭记忆、已成空白 提交于 2020-02-28 06:39:12
问题 In ES5, if I have to refer to the this context of parent function in child function I have to store it in a variable and access it inside child function using that variable. Something like this ... // variant 1 var self = this; this.nums.forEach(function (v) { if (v % 5 === 0) self.fives.push(v); }); ECMAScript has arrow functions so I can avoid this: // variant 2 this.nums.forEach((v) => { if (v % 5 === 0) this.fives.push(v) }) The question that I have is: If I was to declare a variable temp

Difference between protected and protected[this]

眉间皱痕 提交于 2020-02-27 04:45:07
问题 I have the following code: class Base{ protected val alpha ="Alpha"; protected def sayHello = "Hello"; } class Derived extends Base{ val base = new Base; def hello = println(this.alpha +" "+this.sayHello) ; // def hello = println(base.alpha +" "+base.sayHello) ; // don't compile } object MyObj extends App{ val x=new Derived; x.hello; } In class Base , if I label protected with this , the code works as expected; if I don't label it with this , everything works as expected too. Are protected

'this' keyword is undefined inside Mapping Statement (React)

眉间皱痕 提交于 2020-02-16 10:44:08
问题 The this keyword inside the vidsAsHtml mapping function keeps returning undefined. I read this, and a couple other SO questions about this but their solutions did not solve the problem. I'm already using es6 syntax arrow function for the map, but I've also tried putting in this as a second argument, which didn't solve the issue. Curious if anyone knows why 'this' keyword keeps coming up as undefined here. import React, { useState, useEffect } from 'react' import axios from 'axios' const

javascript functions and objects using keyword 'this' does not work

情到浓时终转凉″ 提交于 2020-02-12 02:39:50
问题 my question here is about functions and objects in javascript. I have three questions that stems from one to other. In the below example, I try to access the value of 'a' in test, but I get undefined. but I create a new object of test, then I am able to access the 'a' value and change it. //create a function called test var test=function() { this.a=2 this.b=3 }; test.a//undefined //create a object called test1 using 'new' test1 = new test(); test1.a//2 //change the value of a in test1 test1.a

jQuery - 'this' selector doesn't work inside callback function [duplicate]

筅森魡賤 提交于 2020-02-07 12:27:52
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: $(this) doesn't work in a function I'm writing post removing code in jQuery, The removing itself is made via post-request to backeds, after server returns 200, I want to delete this post on client-side. $('.delete-post').click(function() { $.post($(this).attr('href'), {}, function(data) { $(this).closest('.post').remove(); }); return false; }); However, I've noticed that inside function(data) {...) selector