0

I have small application in Famo.us framework I have two javascript files.. (1) App.js (2) Page.js

(1)App.js is as below

     var Surface         = require('famous/core/Surface');
        var ImageSurface    = require('famous/surfaces/ImageSurface');
        var Modifier        = require('famous/core/Modifier');
        var Transform       = require('famous/core/Transform');
        var View            = require('famous/core/View');
        var PageSwipe       = require('./PageSwipe');

        var PageView        = require('./Page');

function App() {
     var pageView = new PageView({});
        pageView.AddPage('Ghanshyam');
        }

(2) Page.js is as follows:

        var Surface          = require('famous/core/Surface');
            var Modifier         = require('famous/core/Modifier');
            var Transform        = require('famous/core/Transform');
            var View             = require('famous/core/View');
            var ImageSurface     = require("famous/surfaces/ImageSurface");
            var ContainerSurface = require("famous/surfaces/ContainerSurface");
            var StateModifier = require('famous/modifiers/StateModifier');
             var Draggable = require("famous/modifiers/Draggable")

            function Page() {}
function AddPage(url)
    {
        alert(url);
    }

i have created function named AddPage(url) in Page.js file. i want to call this function from App.js as described in constructor of App.js with passing Parameter url. how to call it and how to pass parameters in function ??

ghanshyam.mirani
  • 3,075
  • 11
  • 45
  • 85

1 Answers1

0

You need to make a public function to call it from another view. In javascript you create prototypes. You should look the Timbre menu demo, where famo.us view logic is described and you can find empty view file what to use as a starting point.

   //In Page.js the first function is the constructor
   function Page() {
       View.apply(this, arguments);
   }

   //Public function seen from App.js 
   Page.prototype.addPage(parameter) {
        console.log(parameter);
   }

   //In App.js, call the function
   var myPage = new Page();
   myPage.addPage('hello');