Not sure what I am missing here
I have been developing in php for about a year now, and i just started working with javascript and jquery. I believe were my problem lies is the variable scope, but i am not too sure whats wrong
- var x = 'test';
- $(document).ready(function(){
- var func = function(){
- return {
- trigger: function() {
- x = 'yay';
- },
-
- display: function() {
- return x;
- }
- };
- };
- var result = new func();
-
- $('#click').click(function(){
- result.trigger();
- });
- $('#show').append(result.display());
- });
So, in my example above, what i am trying to do, is display 'test'. But when the client clicks #click, for it to display 'yay'. My problem is that no matter what i try, the trigger function is not updating the global variable to yay, and display is still showing 'test'.
I know i am missing something or missing the whole concept of javascript/jquery.