Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19

Discussione: IE 5 mac

  1. #1

    IE 5 mac

    qualcuno sa dirmi cosa il seguente codice ritorna in IE 5 mac ?
    e anche in altri browser diversi da FF,Netscape,Opera e IE ?

    codice:
    function isFunction(what){
    return (typeof(what)==="function" && (typeof(what.toSource)!=="undefined" && what.toSource().charAt(0)!="/"))?true:false;
    }
    
    alert(isFunction(new RegExp())); // -> false
    alert(isFunction(function(){}));   // -> true
    ps. se ve lo state chiedendo e' per testare la soluzione al RegExp typeof bug
    vedere http://mykenta.blogspot.com/2006/10/...nd-typeof.html per spiegazioni dettagliate

  2. #2
    io non vorrei fare il guastafeste ma per sapere se una variabile è una funzione basta fare così:


    codice:
    function isFunction(f) {
    	return typeof(f) == "function" || f.constructor == Function
    };
    dovrebbe funzionare su tutti ... e stando alla PHP_Serializer questo metodo non ha mai cannato.




    [edit]
    oooops ... correggo, sulla PHP_Serializer uso instanceof ... quindi la funzione dovrebbe essere così (mix delle due)

    codice:
    function isFunction(f) {
    	return	typeof(f) == "function" || 
    		f.constructor == Function || 
    		f instanceof(Function)
    };

    [edit 2]
    per avere compatibilità anche con IE4 ...
    codice:
    function isFunction(f) {
    	return	typeof(f) == "function" || 
    		f.constructor == Function || 
    		eval("f instanceof(Function)")
    };
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  3. #3
    Originariamente inviato da andr3a
    io non vorrei fare il guastafeste ma per sapere se una variabile è una funzione basta fare così:


    codice:
    function isFunction(f) {
    	return typeof(f) == "function" || f.constructor == Function
    };
    dovrebbe funzionare su tutti ... e stando alla PHP_Serializer questo metodo non ha mai cannato.
    siccome typeof(f) == "function" da true su FF per una RegExp sei afflitto dal bug poichè (true || qualsiasicosa) tornerà true per la RegExp .
    prova
    isFunction(new RegExp())

    ...almeno che tu non consideri una RegExp una function

  4. #4
    Originariamente inviato da andr3a

    [edit]
    oooops ... correggo, sulla PHP_Serializer uso instanceof ... quindi la funzione dovrebbe essere così (mix delle due)

    codice:
    function isFunction(f) {
    	return	typeof(f) == "function" || 
    		f.constructor == Function || 
    		f instanceof(Function)
    };
    .. la mia soluzione serve appunto per evitare istanceOf

    comunque non ci siamo ancora true||qualsiasicosa||qualsiasialtracosa sempre = true

  5. #5
    codice:
    function isFunction(f) {
    	return	(typeof(f) == "function" || 
    		f.constructor == Function || 
    		eval("f instanceof(Function)")) &&
    		f.constructor !== RegExp
    };



    P.S. la prima seri di OR è perchè Safari ed altri considerano il typeof come "object" ... non è detto quindi che una funzione ritorni typeof function pure essendo una funzione
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  6. #6
    Originariamente inviato da andr3a
    codice:
    function isFunction(f) {
    	return	(typeof(f) == "function" || 
    		f.constructor == Function || 
    		eval("f instanceof(Function)")) &&
    		f.constructor !== RegExp
    };



    P.S. la prima seri di OR è perchè Safari ed altri considerano il typeof come "object" ... non è detto quindi che una funzione ritorni typeof function pure essendo una funzione
    beh, ma allora basterebbe
    codice:
    function isFunction(f){
    return	(typeof(f) == "function" && f.constructor !== RegExp)
    }
    ora chi mi testa queste 2 funzioni in IE5mac?

    EDIT: eppure ho testato su swift e funziona..

  7. #7
    Originariamente inviato da kentaromiura
    beh, ma allora basterebbe
    codice:
    function isFunction(f){
    return	(typeof(f) == "function" && f.constructor !== RegExp)
    }
    il P.S. l'hai saltato a piedi pari, giusto ?


    semetti && col typeof == "function" Safari ed altri ti diranno che non è una funzione



    teoricamente basta controllare il constructor ... tecnicamente dovresti controllare typeof || instanceof

    non ho capitop perchè non vuoi usare instanceof ... come ti ho già detto con quel modo, usato nella PHP_Serializer, mai avuto un problema e al limite devi aggiungere && .constructor !== RegExp
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  8. #8
    codice:
    function isA(type) {return this.constructor == type};
    
    alert([
    	isA.call({}, Object),				// true
    	isA.call("Hello", String),			// true
    	isA.call(new String, String),			// true
    	isA.call(function(){return false}, Function),	// true
    	isA.call(new Function(), Function),		// true
    	isA.call(/test/, Function),			// false
    	isA.call(/test/, RegExp),			// true
    	isA.call(new RegExp, Function),			// false
    	isA.call(new RegExp, RegExp),			// true
    	isA.call(RegExp, RegExp),			// false
    	isA.call(RegExp, Function)			// true
    ]);

    però se ho usato typeof ed instanceof misa che c'è un motivo .. che non ricordo




    [edit]
    facciamolecose semplici eper tutti va ...
    codice:
    function is(obj, type){return obj.constructor == type};
    
    
    alert([
    	is({}, Object),				// true
    	is("Hello", String),			// true
    	is(new String, String),			// true
    	is(function(){return false}, Function),	// true
    	is(new Function(), Function),		// true
    	is(/test/, Function),			// false
    	is(/test/, RegExp),			// true
    	is(new RegExp, Function),		// false
    	is(new RegExp, RegExp),			// true
    	is(RegExp, RegExp),			// false
    	is(RegExp, Function)			// true
    ]);
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  9. #9
    Originariamente inviato da andr3a
    il P.S. l'hai saltato a piedi pari, giusto ?
    no, l'ho visto dopo averti risposto prima non c'era(vedi l'edit)

    tu dici "Safari ed altri ti diranno che non è una funzione"
    puoi motivarmi con dei test? ho testato in Swift e non ho avuto problemi
    So che in FF hanno sbagliato la typeof di RegExp facendo ritornare function.

    mi servono alcuni test su Mac ora.

    perche' non voglio usare istanceOf ? perche' non funziona in IE4 e "mi sembra" in IE5mac.

  10. #10
    typeof(variable) non ritorna "function" in alcuni browser anche se variable è una funzione.


    [edit]
    per farla breve, typeof da solo non è affidabile

    codice:
    var test = new String("test");
    alert(test);		// "test"
    alert(typeof(test));	// object
    
    switch(test) {
    	case String:
    		alert("switch OK");	// non lo leggerai mai
    		break;
    };
    
    alert(test.constructor == String);	// true
    alert(typeof(test) == "string" || test instanceof String);	// true
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.