'Class'에 해당되는 글 3건

  1. 2020.05.25 [Javascript] JQuery @(at) 처리 문제.
  2. 2009.01.15 [펌]Perl OOP
  3. 2008.02.20 javascript object, class & inheritance, sigletons

[Javascript] JQuery @(at) 처리 문제.

ITWeb/개발일반 2020. 5. 25. 12:19

$('#@id').removeClass('new').addClass('old');

 

여기서 @ 때문에 jquery 내부에서 오류가 발생을 합니다.

이럴 경우 DOM 을 직접 컨트롤 해주셔서 해결 하시면 됩니다.

 

var policyId = 'result' + policyName;

var el = document.getElementById(policyId);

 

el.classList.remove('new');

el.classList.add('old');

:

[펌]Perl OOP

ITWeb/개발일반 2009. 1. 15. 19:27

급해서.. 스크랩 부터.. ^^;

원본문서 : http://www.bjnet.edu.cn/tech/book/perl/ch19.htm

Chapter 19

Object-Oriented Programming in Perl

by Kamran Husain


CONTENTS
Listing 19.1. The initial Cocoa.pm package. package Cocoa;
sub new {

    my $this = {};  # Create an anonymous hash, and #self points to it.

    bless $this;       # Connect the hash to the package Cocoa.

    return $this;     # Return the reference to the hash.

    }



1;
Listing 19.2. Creating the constructor.
1  #!/usr/bin/perl

2  push (@INC,'pwd');

3  use Cocoa;

4  $cup = new Cocoa;
sub new {

        my $class = shift;        # Get the request class name

        my $this = {};

        bless $this, $class        # Use class name to bless() reference

        $this->doInitialization();

        return $this;

    }

 

더 자세한 건 사이트 들어가서 보삼.. ㅎㅎ

perl 로 class 만드는 것 중 기본은.. package 를 만드는 것이고 pacakge 의 끝은 1; 로 끝나야 한다는거.. ㅎㅎ

:

javascript object, class & inheritance, sigletons

ITWeb/개발일반 2008. 2. 20. 17:08

 
Class & Inheritance

사용자 삽입 이미지



















 
Class & Inheritance
-Prototypal Inheritance
var oldObject = {
    firstMethod: function () { alert("first"); },
    secondMethod: function () { alert("second"); }
};
var newObject = new Object(oldObject);
newObject.thirdMethod = function () { alert("third"); };
var myDoppelganger = new Object(newObject);
myDoppelganger.firstMethod(); // or
myDoppelganer[“firstMethod”]();
var obj1 = function () {
this.title = "obj1";
}
var obj2 = function () {}
obj2.prototype = new obj1;
var obj2Class = new obj2();
alert(obj2Class.title);
obj1 = {
title:"obj1_"
}
obj2 = new Object(obj1);
alert(obj2.title);

 
-Method apply (Member variable)
§Function.apply(thisArg[, argArray])
function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}
 
function RentalCar(carNo, make, model, year) {
  this.carNo = carNo;
  Car.apply(this, new Array(make, model, year));
}
 
myCar = new RentalCar(2134,"Ford","Mustang",1998);
document.write("Your car is a " + myCar.year + " " + myCar.make + " " + myCar.model + ".");

 
-Method apply (Member function)
§function TopClass (name, value) {
§ this.name = name;
§ this.value = value;
§ this.getAlertData = function () {
§ alert(this.name);
§ alert(this.value);
§ }
§}
§function SubClass (name, value, dept) {
§ this.dept = dept;
§ TopClass.apply(this, arguments);
§ this.getView = function () {
§ this.getAlertData();
§ }
§}
§//SubClass.prototype = new TopClass();
§var objSubClass = new SubClass("상위클래스","super","community");
§objSubClass.getView();

 
-Method call
§Function.call(thisArg[, arg1[, arg2[, ...]]])
function car(make, model, year) {
    this.make = make, this.model = model, this.year = year;
}
 
function hireCar(carNo, make, model, year) {
    this.carNo = carNo, car.call(this, make, model, year);
}

 
-Prototype
Profiler = function () {..}
Profiler.prototype.name = function () {..}
-Namespace
YAHOO = {};
-new operator
function object(o) {
function F() {};
F.prototype = o;
return new F();
}
classA = new Profiler(); or classA = object(Profiler);

 
-Encapsulate (Parasitic)
YAHOO = {};
YAHOO.Trivia = function () {
    var privateVar = "showPoser";
    function privateNextPoser() {
        alert("getNextPoser");
    }
    return {
        getNextPoser: function (cat, diff) {
            privateNextPoser();
        },
        showPoser: function () {
            alert(privateVar);
        }
    };
} ();
function getFunc() {
var oObj = YAHOO.Trivia;
oObj.getNextPoser();
}
YAHOO = {};
YAHOO.Trivia = function () {
    var privateVar = "showPoser";
    function privateNextPoser() {
        alert("getNextPoser");
    }
    return {
        getNextPoser: function (cat, diff) {
            privateNextPoser();
        },
        showPoser: function () {
            alert(privateVar);
        }
    };
};
function getFunc() {
var oObj = new YAHOO.Trivia();
oObj.getNextPoser();
}

 
-Singletons
var singleton = function () {
    var privateVariable;
    function privateFunction(x) {
        ...privateVariable...
    }
    return {
        firstMethod: function (a, b) {
            ...privateVariable...
        },
        secondMethod: function (c) {
            ...privateFunction()...
        }
    };
}();





: