javascript - How to call the function inside the own function -


ninjas.

i know 2 things.

  1. how call functions 'initialize()' , 'fillvalidateview()'. wrote want call these functions inside following code.

  2. i'm new javascript programing. know if following code right implement page transitions.

html

<!doctype html> <html> <head>     <meta charset="utf-8" /> </head> <body>     <div id="header">         <p></p>     </div>      <div id="main">         <div id="validate_or_import">             <input type="button" id="go_validate" value="validate data">             <inp ut type="button" id="go_import" value="import data">         </div>     </div>  </body> </html> 

javascript

$(function () {      var view = function () {         this.title = ''     };      view.prototype = {         initialize: function () {             this.title = '';             this.tiles = [];             $('#main').children().hide();         },         render: function () {             $('#header p').html(this.title);             jquery.each(this.tiles, function () {                 this.show();             });         },         fillfirstview: function () {             this.title = 'select want';             this.tiles.push($('#validate_or_import'));             $('#go_validate').on('click', function () {                 // want call 'initialize()' , 'fillvalidateview()' here!!!!!             });             $('#go_import').on('click', function () {                 alert('not implemented yet');             });         },         fillvalidateview: function () {             this.title = 'validate data';             //i write more view         }     };      var view = new view();     view.initialize();     view.fillfirstview();     view.render();  }); 

(1) it's bit tricky because value of this won't original object in callback. do:

var = this; $('#go_validate').on('click', function () {     that.initialize();   }); 

or:

$('#go_validate').on('click', (function() {   this.initialize(); }).bind(this)); 

more infos in this keyword: how "this" keyword work?


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -