methods

How do I move a window's position on the computer screen with javascript?

心已入冬 提交于 2019-12-21 17:53:08
问题 I remember seeing a google maps mashup / music video that created, resized, and moved windows on the screen. What javascript methods are used to do this? 回答1: I don't know how reliable this is, but to move the window relative to it's current position you can do this: window.moveBy(250, 250); //moves 250px to the left and 250px down http://www.w3schools.com/jsref/met_win_moveby.asp To move the window to a certain part of the screen: window.moveTo(0, 0); //moves to the top left corner of the

Get all methods and/or properties in a given Perl class or module

一世执手 提交于 2019-12-21 17:37:23
问题 I'm dealing with an apparent simple issue. I'm writing a module similar to UML::Class::Simple but with some improvements. Summarizing, the idea is to retrieve a record card for each module in a given source, containing information about the Methods, Properties, Dependencies and Children. My current problem is getting Methods and Properties for each module. Let's see the code I've already written: use Class::Inspector; use Data::Dumper; sub _load_methods{ my $pkg = shift; my $methods = Class:

setting objects equal to eachother (java)

青春壹個敷衍的年華 提交于 2019-12-21 17:36:50
问题 So I have a class called Person which looks like this public class Person { private String personName; public String toString(){ return personName; } public Person(String personName){ this.personName = personName; } } and another class in which I am creating the object(s) person public class IdanJavaTask { public static void main(String[] args) { Person p1 = new Person("Bob"); System.out.println("p1 : " + p1); Person p2 = new Person("Joe"); System.out.println("p2 :" + p2); } } so far

Calling a method of One View controller from Another View Controller

怎甘沉沦 提交于 2019-12-21 17:29:52
问题 I have a method "someMethod" declared in OneViewController.h @interface OneViewController { UIView *tempView; .. } -(void) someMethod ; @end and implemented in OneViewController.m file @implementation OneViewController -(void) someMethod { tempView = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 200, 250)]; tempView.backgroundColor = [UIColor yellowColor]; if([[self.view subviews] containsObject:tempView]) [tempView removeFromSuperView]; else [self.view addsubview:tempView]; } I want to

Decorating method (class methods overloading)

a 夏天 提交于 2019-12-21 17:28:17
问题 Inspired by Muhammad Alkarouri answer in What are good uses for Python3's "Function Annotations" , I want to do this multimethod for methods, not regular functions. However, when I do this registry = {} class MultiMethod(object): def __init__(self, name): self.name = name self.typemap = {} def __call__(self, *args): types = tuple(arg.__class__ for arg in args) # a generator expression! function = self.typemap.get(types) if function is None: raise TypeError("no match") return function(*args)

Difference Class and Instance Methods

自作多情 提交于 2019-12-21 17:17:08
问题 Whats the difference between class methods and Instance methods. Why do we need them separately? Can somebody please explain? Class and Instance Methods • Instances respond to instance methods - (id)init; - (float)height; - (void)walk; • Classes respond to class methods + (id)alloc; + (id)person; + (Person *)sharedPerson; Taimur 回答1: An instance method is only available on an instance of the class, while a class method does not need an instance but is available on the class. Class Methods are

Why does this class have two constructors?

隐身守侯 提交于 2019-12-21 17:02:58
问题 I see this in the slide that aims to illustrate constructors. I'm confused now because it has two constructors that have the same job accept setting gpa to zero in the second one. Why does the coder need to repeat this.id = id; this.name = name; again? Why does this class even need two constructors? class Student{ private int id; private String name; private double gpa; public Student(int id, String name, double gpa){ this.id = id; this.name = name; this.gpa = gpa; } public Student(int id,

What is the point of Ruby's method unbinding mechanism?

折月煮酒 提交于 2019-12-21 10:33:26
问题 Method#unbind returns an UnboundMethod reference to the method, which can later be bound to another object using UnboundMethod#bind. class Foo attr_reader :baz def initialize(baz) @baz = baz end end class Bar def initialize(baz) @baz = baz end end f = Foo.new(:test1) g = Foo.new(:test2) h = Bar.new(:test3) f.method(:baz).unbind.bind(g).call # => :test2 f.method(:baz).unbind.bind(h).call # => TypeError: bind argument must be an instance of Foo Initially, I thought this is incredibly awesome,

Python: Do something for any method of a class?

纵饮孤独 提交于 2019-12-21 07:18:20
问题 Say I have a class with a bunch of methods: class Human(): def eat(): print("eating") def sleep(): print("sleeping") def throne(): print("on the throne") Then I run all the methods with John=Human() John.eat() John.sleep() John.throne() I want to run print("I am") for each method being called. So I should get something like I am: eating I am: sleeping I am: on the throne Is there a way to do this without having to reformat each method? 回答1: If you can't change how you call your methods you

Updating Class variable within a instance method

狂风中的少年 提交于 2019-12-21 07:15:42
问题 class MyClass: var1 = 1 def update(value): MyClass.var1 += value def __init__(self,value): self.value = value MyClass.update(value) a = MyClass(1) I'm trying to update a class variable( var1 ) within a method( _ init _ ) but I gives me: TypeError: unbound method update() must be called with MyClass instance as first argument (got int instance instead) I'm doing this because I want easy access to all variables in a class by calling print MyClass.var1 回答1: You are confusing classes and