gruss "God's Boss",
- Boolean.prototype.ifTrue
- Boolean.prototype.ifFalse
hey, das war doch nur ein 5-minuten spass ...
...
Zu diesen beiden Methoden hätte ich direkt einen Verbesserungsvorschlag:
Füge ihnen einen weiteren optionalen Parameter hinzu, der ein Objekt
beinhalten kann, in dessen Kontext die übergebene Funktion ausgeführt wird.
...
na gut, Du hast ja recht. es liegt tatsaechlich auf der hand, dies zu tun.
done:
/*
[link:http://de.wikipedia.org/wiki/Smalltalk-80_(Programmiersprache)#IF-Anweisung]
*/
[link:http://www.pseliger.de/jsExtendedApi/jsApi.Boolean.ifTrue.ifFalse.dev.js@title=Boolean.prototype.ifTrue] = (function (fct, target/*optional:[object|function]*/) { // [caseTrue], [ifTrue], [ifTrueDo]
var isTrue = this.valueOf();
if (isTrue && (typeof fct == "function")) {
fct.call(((typeof target == "undefined") || ((typeof target == "obj") && !target)) ? (null) : (target));
}
return isTrue;
});
Boolean.prototype.ifFalse = (function (fct, target/*optional:[object|function]*/) { // [caseFalse], [ifFalse], [ifFalseDo]
var isTrue = this.valueOf();
if (!isTrue && (typeof fct == "function")) {
fct.call(((typeof target == "undefined") || ((typeof target == "obj") && !target)) ? (null) : (target));
}
return isTrue;
});
/*
[link:http://jconsole.com]
*/
(7 < 6).ifTrue(function () {
print(" ... is true.");
}).ifFalse(function () {
print(" ... is false.");
});
(7 > 6).ifTrue(function () {
print(" ... is true.");
}).ifFalse(function () {
print(" ... is false.");
});
danke und so long - peterS. - pseliger@gmx.net
--
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]