this

JavaScript | Angular | Controller As Syntax: Cannot Use `this`

天大地大妈咪最大 提交于 2019-11-29 12:51:57
Cannot Use ControllerAs this Can anyone explain the following scenario to me, please? Works ng-controller="Parent as thus" Breaks ng-controller="Parent as this" That single letter which makes it a keyword -- which I want -- wrecks the forest. Why is this? P.S. I'm aware of the vm convention, but I find it disturbs portability of controllers/viewmodels. The problem is certainly not that this is a reserved word in JavaScript. There is no rule in the controller as syntax that says you would need to assign the value of this to a variable with the same name as the controller and I'm pertty sure

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

妖精的绣舞 提交于 2019-11-29 12:48:32
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=4 test1 //Object { a=4, b=3} while trying to find why this happens, I came across this javascript

address of this

社会主义新天地 提交于 2019-11-29 12:36:34
问题 I try to find address of this pointer, but this code is showing a strange error: #include <iostream> using namespace std; class Base { public: void test() { void *address_of_this =&this; cout<<address_of_this<<endl; } }; int main() { Base k; k.test(); return 0; } //error non-lvalue in unary'&' Can you explain this error ? Also point that what is illegal in taking address of this ? 回答1: this is a pointer containing the address to the "current object". It is not a variable that is stored

Jquery AJAX call: $(this) does not work after success

拟墨画扇 提交于 2019-11-29 11:42:48
I am wondering why $(this) does not work after a jQuery ajax call. My code is like this. $('.agree').live("click", function(){ // use live for binding of ajax results var id=($(this).attr('comment_id')); $.ajax({ type: "POST", url: "includes/ajax.php?request=agree&id="+id, success: function(response) { $(this).append('hihi'); } }); return false; }); Why doesnt the $(this) work in this case after ajax call? It would work if I use it before the ajax but no effect after. In a jQuery ajax callback, "this" is a reference to the options used in the ajax request. It's not a reference to a DOM element

Accessing this from within an object's inline function

对着背影说爱祢 提交于 2019-11-29 11:20:13
问题 I'm having difficulty referencing "this" from within a javascript inline function, within an object method. var testObject = { oThis : this, testVariable : "somestring", init : function(){ console.log(this.testVariable); // outputs testVariable as expected this.testObject.submit(function(){ var anotherThis = this; console.log(this.testVariable) // undefined console.log(oThis.testVariable) // undefined console.log(testObject.testVariable) // outputs testVariable console.log(anotherThis

How do I get SWIG to automatically wrap an emulated “this” pointer to a C struct?

我是研究僧i 提交于 2019-11-29 10:53:55
I've got a simple C "class" I have implemented, using function pointers in a struct to implement the member functions, and passing a pointer to the struct as the first argument to each function, similar to the implicit "this" pointer in C++. %module mytest %{ typedef struct mytest mytest; struct mytest { int data; int (*func1)(mytest *,int); void (*func2)(mytest *,int); }; int f1(mytest *me,int n) { return me->data + n; } void f2(mytest *me,int n) { me->data += n; } mytest *mytestNew(int n) { mytest *me = (mytest*) malloc(sizeof(mytest)); me->data = n; me->func1 = f1; me->func2 = f2; return me

React this is undefined

我与影子孤独终老i 提交于 2019-11-29 10:51:30
React this is undefined in promise . Here is my code: export default class Album extends React.Component { constructor(props) { super(props); } componentDidMount () { console.log(this.props.route.appState.tracks); // `this` is working axios({ method: 'get', url: '/api/album/' + this.props.params.id + '/' + 'tracks/', headers: { 'Authorization': 'JWT ' + sessionStorage.getItem('token') } }).then(function (response) { console.log(response.data); this.props.route.appState.tracks.concat(response.data); // 'this' isn't working }).catch(function (response) { console.error(response); //sweetAlert(

Returning *this in member functions

只谈情不闲聊 提交于 2019-11-29 09:23:39
I recently used a library that allows the following type of syntax: MyClass myObject; myObject .setMember1("string value") .setMember2(4.0f) .setMember3(-1); Obviously this is accomplished by having the setters return a MyClass & type; something like return *this. I like the way this code looks, but I don't see it a lot. When that happens I'm usually suspicious as to why. So, is this a bad practice? What are some of the implications of doing it like this? This is sometimes referred to as the Named Parameter Idiom or method chaining. This isn't bad practice, it can aid readability. Consider

Where's the difference between self and $this-> in a PHP class or PHP method?

ε祈祈猫儿з 提交于 2019-11-29 09:19:17
Where's the difference between self and $this-> in a PHP class or PHP method? Example: I've seen this code recently. public static function getInstance() { if (!self::$instance) { self::$instance = new PDO("mysql:host='localhost';dbname='animals'", 'username', 'password');; self::$instance-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$instance; } But I remember that $this-> refers to the current instance (object) of a class (might also be wrong). However, what's the difference? $this refers to the instance of the class, that is correct. However, there is also

Does every c++ member function take `this` as an input implicitly?

泪湿孤枕 提交于 2019-11-29 09:07:07
When we create a member function for a class in c++, it has an implicit extra argument that is a pointer to the calling object -- referred as this . Is this true for any function, even if it does not use this pointer. For example, given the class class foo { private: int bar; public: int get_one() { return 1; // Not using `this` } int get_bar() { return this->bar; // Using `this` } } Would both the functions ( get_one and get_bar ) take this as an implicit parameter, even though only one of them actually uses it? It seems like a bit of a waste to do so. Note : I understand the correct thing to