Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 25th, 2011, 02:26 AM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Red face what does the this and self mean in the code???

<code>
var Scroll = new function(){
this.delay = 2000; //延迟的时间
this.height = 20; //行的高度
this.step = 4; //步长
this.curHeight= 0;
this.stimer = null;
this.timer = null;
this.start = function(){ //开始翻页-调用move方法
this.move();
}
this.move = function(){
var self = this;
if(this.curHeight == this.height) //如果显示完一行
{
this.timer = setTimeout(function(){ //使用定时器-定时下一行的翻页时间
self.move();
}, this.delay);
this.curHeight = 0;
if(this.element.scrollTop >= this.element.scrollHeight - this.height){ //滚动信息已经完毕
this.element.scrollTop = 0;
}
return true;
}
this.element.scrollTop += this.step;
this.curHeight += this.step;
this.timer = setTimeout(function(){ //设置自动翻页定时器
self.move();
}, 30);
}
this.stop = function(){ //清除定时期,停止滚动翻页
clearTimeout(this.timer);
}
}
</code>

anybody can help me analysize the code? it's too difficult to me!
 
Old February 18th, 2012, 04:06 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile step 1

1- first note

Code:
var x = new function(){
    this.y = 2000; 
}
the above statement creates an object (class) named: x
and y property is added to x. 'this' refers to the object (x)

Code:
x.y = 288;

// or

x["y"] = 288;
__________________
happy every time, happy every where

Reza Baiat
 
Old February 18th, 2012, 04:09 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile step 2 - adding function (method) to object

Code:
var x = new function(){
    this.y = 2000;
    this.move = function(){
        alert('move function called');
    };
}

x.move(); // shows alert
you can add methods like above
__________________
happy every time, happy every where

Reza Baiat
 
Old February 18th, 2012, 04:10 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile step 3- call other methods

Code:
var x = new function(){
    this.y = 2000;
    this.move = function(){
        startMove();
        // ...
        endMove();
    };
    this.startMove = function(){
        alert('started ... ');
    };
    this.endMove = function(){
        alert('ended ... ');
    };
}

x.move(); // shows alerts
you can call other methods like above
__________________
happy every time, happy every where

Reza Baiat

Last edited by irProject; February 18th, 2012 at 04:16 AM..
 
Old February 18th, 2012, 09:23 AM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

thank you very much!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Double clicking control does not add code to Code Behind Paul Walton BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 September 25th, 2009 05:40 PM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.